|
Duplicate :
|
|
|
Duplicate :
|
|
|
Duplicate :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
A DESCRIPTION OF THE REQUEST :
Currently, the for/in statement (ie for(Date date : collection)...) only supports Iterable and Object[] as the source of objects to iterate over. There is no reason why this statement should not support Iterators directly. For instance, the following code should work
List<Integer> myList = buildIntegers();
for (Integer integer : myList.iterator())
System.out.println(integer);
JUSTIFICATION :
Sometimes I will have a method other than iterator() that returns the iterator I want to travers. For instance, I could have a method that returns an iterator over a subset of objects in the source object...
Iterator<Integer> getOddIntegers();
Right now, I'm forced to use old style for loops with iterators. I'd like to be able to type
for (Integer integer : myList.getOddIntegers())
System.out.println(integer);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If I pass an iterator as the argument to a for/in loop after the colon, it should just work.
ACTUAL -
I get a compile error when I try this now
|