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

Brian Goetz brian.goetz at oracle.com
Thu Mar 14 14:21:04 UTC 2019



> It think this alternative is not given fair comparison. 1st this is an 
> instance method, so the foreach loop should read:
>
> for (T t : stream.asIterable()) {
>     ...
> }

Let's keep sight of the goal here, which is: people find it a gap that 
Stream does not play cleanly with foreach.  And the main knock against 
this approach (besides the chorus of "that's not what we wanted" we are 
sure to get) is that it is not really much more discoverable than some 
of the other workarounds (such as casting stream::iterator to Iterable.)

>
>
> And now for something more controversial...
>
> Is changing the language really out of the picture here?

Yes.  This issue was extensively litigated during JSR-335, and it was 
decided that one language-to-library tunnel (Iterable) here was all we 
wanted.  And there's been no new evidence since then that we want to 
change the language for this.

There's a reason it took as long as it did for Stuart to come up with 
this proposal; all the options were known for years, they all have 
problems, and the net benefit is still relatively narrow, which means we 
don't have a lot of budget before the cost-benefit becomes negative.  I 
think the option proposed is the least-worst, and people still seem to 
really want to be able to foreach over streams.



More information about the core-libs-dev mailing list