PROPOSAL: Enhanced for each loop iteration control

Stephen Colebourne scolebourne at
Mon Mar 30 16:46:04 PDT 2009

Stefan Schulz wrote:
> Frankly, I cannot see a great advantage of:
>    for (Foo foo : fooList : it) {
>      ...
>    }
> saving two lines of code over:
>    Iterator<Foo> it = fooList.iterator();
>    while (it.hasNext()) {
>      Foo foo =;
>      ...
>    }

The former captures the *intent* of the loop. The latter is all about 

> by adding two wrappers and stuff to the code in the background.

The proposal discusses possible optimisations, however I suspect that 
hohtspot can probably cope with two additional objects being created.

Remember, the extra overhead only happens if you add the optional 
iterator reference.


More information about the coin-dev mailing list