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

Iterator and Enumeration have no toList() method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.5
    • groovy-jdk
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: