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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 6
    • core-libs

      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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: