Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1548

Iterator and Enumeration have no toList() method

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0-JSR-6
    • Fix Version/s: 1.5
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      OS X 10.4.8, Java 1.5

      Description

      I discovered today to my surprise that Iterator (and I presume Enumeration) does not have a toList() method, and that there is no coercion to list:

      groovy> assert [1,2,3,4].iterator() == [1,2,3,4]

      Exception thrown: java.lang.AssertionError: Expression: ([1, 2, 3, 4].iterator() == [1, 2, 3, 4])

      so you try to write it using iterator().toList():

      groovy> assert [1,2,3,4].iterator().toList() == [1,2,3,4]

      Exception thrown: groovy.lang.MissingMethodException: No signature of method java.util.AbstractList$Itr.toList() is applicable for argument types: () values: {}

      Still no joy, so you are left having to do:

      groovy> assert [1,2,3,4].iterator().findAll()

      { true }

      == [1,2,3,4]

      ...which is rather ugly.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              marc@anyware.co.uk Marc Palmer
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: