On Wed, Mar 23, 2011 at 1:23 PM, Russel Winder <[email protected]> wrote:
> Unlike Java which
> chose to ignore iterators à la C++ -- another paradigm war but this one
> was fought in the late 1990s.
>
First of all, before the enhanced for loop came out, Java was using
iterators pretty much everywhere in collection loops:
for (Iterator it = collection.iterator(); it.hasNext(); ) {
Object o = it.next();
}
This followed the techniques made popular by the STL, but it was seen as not
just a lot of boiler plate but also exposing users to needless
implementation details: if all you want is enumerating the objects in a
collection, why should you even care about the concept of iterators?
Thus, the enhanced for loop was born:
for (Object o : collection) {
...
}
No more iterators, much easier to read, and the only objects involved in
this construct are the ones you care about: the collection and the objects
it contains.
> Joshua Bloch has at least acknowledged
> that the Java Collections framework took the wrong architectural
> decision;
>
Uh, citation? We came up with the enhanced for loop precisely to hide
iterators, so I still claim that the enhanced for loop is a big improvement
over what we had before.
Or are you referring to something else?
--
Cédric
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.