Proposal: JDK-8148917 Enhanced-For Statement Should Allow Streams
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Mar 21 13:17:11 UTC 2019
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>, "Stuart Marks" <stuart.marks at oracle.com>
> Cc: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Mardi 19 Mars 2019 00:58:04
> Objet: Re: Proposal: JDK-8148917 Enhanced-For Statement Should Allow Streams
>> 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.)
for some reason i was convinced that IntStream.iterator() was returning a PrimitiveIterator.OfInt and not an Iterator<Integer>,
so yes, it will work but i don't understand why it's not BaseStream instead of Stream<Object> that inherits from Iterable.
And i still think that add IterableOnce is a very bad idea because it's the same trap as trying to introduce an interface UnmodifiableList as subtype of List.
Rémi
More information about the core-libs-dev
mailing list