Details

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

      Description

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

        Activity

        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.

          People

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

            Dates

            • Created:
              Updated: