Shouldn’t this code:
for (String line : conn.list())
{
}
be equal to:
conn.list();
?
It’s not: conn.list() isn’t even invoked in the enhanced-for loop :o
…
I know this is bad design (doing nothing with items in an iterator, shouldn’t have any side-effects) but it should be the equivalent of:
Iterable it = conn.list(); // invokes list()
while(it.hasNext())
{
Iterator i = it.next();
while(i.hasNext())
i.next();
}
which invokes list() no matter what.