Lambdas in for-each loops

Kevin Bourrillion kevinb at google.com
Tue Sep 4 14:26:09 PDT 2012


On Fri, Aug 31, 2012 at 9:22 AM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

It is plausible that an Iterator could be wrapped as an
> Iterable in a for loop via a lambda expression (for (String s : () ->
> stringIterator)), but this doesn't mesh very well with the semantics of
> Iterable."
>

Is this referring to the fact that the Iterable doesn't behave like we
expect (returning multiple independent iterators)?  Because the foreach
loop context is precisely where that issue doesn't matter, so it seems to
present no argument against supporting this.

I've been saying that lambda expressions can be used in any context that
expects an instance of a FI type. It would be nice to have no exceptions to
that, if possible (are there others besides this foreach loop situation?).


More information about the lambda-dev mailing list