Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-JSR-6
-
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.