-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
9
A DESCRIPTION OF THE REQUEST :
The for-each-loop currently only supports arrays and instances of Iterable. There's no reason, why it shouldn't also support the Iterator itself directly.
JUSTIFICATION :
It can be nasty and expensive to wrap an existing iterator with a dummy iterable just to use the nice and handy for each loop.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Iterator it = ...;
for ( Object o : it )
{
}
CUSTOMER SUBMITTED WORKAROUND :
DummyIterable itbl = new DummyIterable( it );
for ( Object o : itbl )
{
}
// or:
while ( it.hasNext() )
{
Object o = it.next();
}
The for-each-loop currently only supports arrays and instances of Iterable. There's no reason, why it shouldn't also support the Iterator itself directly.
JUSTIFICATION :
It can be nasty and expensive to wrap an existing iterator with a dummy iterable just to use the nice and handy for each loop.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Iterator it = ...;
for ( Object o : it )
{
}
CUSTOMER SUBMITTED WORKAROUND :
DummyIterable itbl = new DummyIterable( it );
for ( Object o : itbl )
{
}
// or:
while ( it.hasNext() )
{
Object o = it.next();
}
- duplicates
-
JDK-6312085 enhanced-for statement (for-each loop) should support Iterator
-
- Closed
-