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

Peter Levart peter.levart at
Fri Mar 15 07:03:49 UTC 2019

On 3/15/19 12:16 AM, Stephen Colebourne wrote:
> On Thu, 14 Mar 2019 at 19:45, Brian Goetz <brian.goetz at> wrote:
>> 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.
> IterableOnce.wrap(iterator) ?
> Not providing some kind of connection between these types will look
> pretty silly I think.
> Stephen
That makes sense, yes. As a utility method for adapting in situations 
where there's an unconsumed Iterator at hand and you have to provide a 
"well behaved" IterableOnce. I would call it IterableOnce.of(Iterator) 
as it does not really adapt the Iterator, but creates a factory with 
provided Iterator. Using this would be preferable to sprinkling ad-hoc 
expressions like:

(IterableOnce<T>) () -> iterator

as such IterableOnce instances would not conform to the spec.

Regards, Peter

More information about the core-libs-dev mailing list