Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6389004

(coll) Collections.list should take Iterator, not just Enumeration

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE REQUEST :
      from java.util.Collections:

      public static <T> ArrayList<T> list(Enumeration<T> e)
      Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. This method provides interoperability between legacy APIs that return enumerations and new APIs that require collections.

      from java.util.Enumeration:

      NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

      so, if i have an Iterator (but not a Collection or List) and want a List, i can't use Collections.list because i don't have a legacy Enumeration.

      JUSTIFICATION :
      we're told to prefer Iterator, but are penalized for having one instead of an Enumeration.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      there should be Collections.list(Iterator<T>).

      alternatively, there should be a convenient way to translate an Iterator to an Enumeration, since Enumeration offers less functionality than Iterator. (but do we really want to translate to the non-preferred Enumeration class?)
      ACTUAL -
      there's only Collections.list(Enumeration<T>).

      CUSTOMER SUBMITTED WORKAROUND :
      writing the Iterator-to-List copy longhand.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              smarks Stuart Marks
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: