Details

    • Type: Sub-task Sub-task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0-JSR-3
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None

      Description

      collection.toList() vs. asList()
      // there should be only one variant

        Activity

        Dierk König created issue -
        Guillaume Delcroix made changes -
        Field Original Value New Value
        Fix Version/s 1.0-JSR-4 [ 11905 ]
        Fix Version/s 1.0-JSR-5 [ 12102 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.0-RC-1 [ 12103 ]
        Fix Version/s 1.0-JSR-5 [ 12102 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.0-RC-1 [ 12104 ]
        Fix Version/s 1.0-JSR-6 [ 12103 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.0-RC-1 [ 12104 ]
        Fix Version/s 1.0-final [ 10244 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.1 [ 10436 ]
        Fix Version/s 1.0 [ 10244 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.1-beta-2 [ 10436 ]
        Jochen Theodorou made changes -
        Fix Version/s 1.6-beta-1 [ 14008 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6-beta-1 [ 14008 ]
        Fix Version/s 1.6-beta-2 [ 14261 ]
        Guillaume Delcroix made changes -
        Fix Version/s 1.6-rc-1 [ 14009 ]
        Fix Version/s 1.6-beta-2 [ 14261 ]
        Guillaume Delcroix made changes -
        Fix Version/s 2.0 [ 13489 ]
        Fix Version/s 1.6-rc-1 [ 14009 ]
        Hide
        Paul King added a comment -

        My understanding is as follows:

        • the toList() variant always creates a new list so is suitable where copy semantics is in play (the original list will never be affected as the new list is returned by this method)
        • the asList() is used in places where the original list would be desirable to use (e.g. maybe for modify semantics operations) but some kind of ordering is required (e.g. no point in sorting a vanilla set or map as the original collection is inherently unordered)

        Perhaps the correct approach would have been to not provide things like sort (modify semantics) on collection but only on ordered collections (e.g. List, Queue & LinkedHashSet) and require the user to use toList(), toOrderedSet(), etc. explicitly. Pity Java doesn't have OrderedSet etc. instead of just SortedSet.

        Show
        Paul King added a comment - My understanding is as follows: the toList() variant always creates a new list so is suitable where copy semantics is in play (the original list will never be affected as the new list is returned by this method) the asList() is used in places where the original list would be desirable to use (e.g. maybe for modify semantics operations) but some kind of ordering is required (e.g. no point in sorting a vanilla set or map as the original collection is inherently unordered) Perhaps the correct approach would have been to not provide things like sort (modify semantics) on collection but only on ordered collections (e.g. List, Queue & LinkedHashSet) and require the user to use toList(), toOrderedSet(), etc. explicitly. Pity Java doesn't have OrderedSet etc. instead of just SortedSet.
        Paul King made changes -
        Assignee Paul King [ paulk ]
        Jochen Theodorou made changes -
        Issue Type Improvement [ 4 ] Sub-task [ 7 ]
        Parent GROOVY-5600 [ 138785 ]
        Jochen Theodorou made changes -
        Fix Version/s 3.0 [ 13489 ]
        Jochen Theodorou made changes -
        Parent GROOVY-5600 [ 138785 ]
        Issue Type Sub-task [ 7 ] Improvement [ 4 ]
        Jochen Theodorou made changes -
        Parent GROOVY-4506 [ 117493 ]
        Issue Type Improvement [ 4 ] Sub-task [ 7 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12730279 ] Default workflow, editable Closed status [ 12742241 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12968695 ] Default workflow, editable Closed status [ 12976449 ]

          People

          • Assignee:
            Paul King
            Reporter:
            Dierk König
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development