Feedback and comments on ARM proposal
Joshua Bloch
jjb at google.com
Mon Mar 9 20:13:27 PDT 2009
Roel,
There were several reasons. The main reason was that we wanted the for-each
loop to be side-effect free. Had we allowed Iterators, two consecutive
for-each statements on the same Iterator would have been legal, but would
have had very different semantics from two consecutive for-each statements
over the same Iterable. The former would have traversed the collection
once, while the latter traversed it twice. We thought this might lead to
bugs. Also it allowed us to avoid the issue of what to do if the object to
be iterated over implemented both Iterable and Iterator. There were people
on the expert group who argued to allow Iterator, but in the end it was
decided we decided that it was best not to support it.
Regards,
Josh
On Mon, Mar 9, 2009 at 4:37 PM, Roel Spilker <r.spilker at gmail.com> wrote:
> A bit off-topic, and just out of curiosity: What is the reason the for-each
> cannot work on Iterators? Is it just the problem when both Iterable and
> Iterator are implemented, or were there other reasons as well?
>
> Roel
>
>
> > At this point, I think only one name will be supported (close), so the
> > problem goes away. We went through the same conniptions with the
> for-each
> > statement (Does it work on Iterator as well as Iterable? What happens if
> > you implement both?).
> >
> >
>
>
More information about the coin-dev
mailing list