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

Brian Goetz brian.goetz at
Mon Mar 18 23:58:04 UTC 2019

> My fear is more than we will want in the future to have one code for all kinds of Stream, but Stream<Object> will have to implement Iterable<Object> while Stream<int> will not, this not something you can actually do with the current generics, we may be able to do that with the reified generics but some languages that already have reified generics like Swift are not able to do that.
> So by making Stream<T> to have different set of supertypes than Stream<int>, you are forcing the future reified generics implementation to work on this case because we will never introduce an implementation of reified generics that doesn't support the classe of java.util.

This will work fine; Stream<T> <: IterableOnce<T>, and when we can 
instantiate T=int in the first, we'll be able to do so in the second as 
well.  (Having spent hundreds of hours banging my head against how we're 
going to migrate collections and stream to specialization, this one is 
not even on the list.)

More information about the core-libs-dev mailing list