Proposal: JDK-8148917 Enhanced-For Statement Should Allow Streams

Brian Goetz brian.goetz at
Thu Mar 14 19:45:41 UTC 2019

> A new concern from me is that this change would allow Iterable and
> Stream to be used in foreach, but not Iterator. This seems like an
> odd/sharp conceptual edge.

Not actually a new concern — this was discussed back in JSR 335 as well.  

> Why not make `Iterator` implement `IterableOnce`? The default method
> would obviously just return `this`.

Such a default would not conform to the contract, as IO requires that subsequent calls throw.  

More information about the core-libs-dev mailing list