Stream.generate
Paul Sandoz
paul.sandoz at oracle.com
Wed Jul 22 08:10:56 UTC 2015
On 20 Jul 2015, at 19:08, Remi Forax <forax at univ-mlv.fr> wrote:
> Hi all, hi Paul,
> I've found that the signature of Stream.generate doesn't to use a wildcard hence some program are rejected even if there are valid, by example:
> public static void main(String[] args) {
> Supplier<String> supplier = () -> "hello";
> Stream<CharSequence> s = Stream.generate(supplier);
> }
>
> The fix is simple, in interface Stream, generate should be declared like this :
> public static<T> Stream<T> generate(Supplier<? extends T> s)
> and
> the field 's' of the InfiniteSupplyingSpliterator.OfRef should be also declared as a Supplier<? extends T>.
>
I believe such changes to Stream.generate are backwards compatible because overriding is not possible. (In addition static method on an interface are scoped to that interface, but i am not sure if that matters in this case.)
We could also adjust Stream.iterate as well:
public static<T, S extends T> Stream<T> iterate(final S seed, final UnaryOperator<S> f)
Seems appropriate for consistency with Stream.generate. I presume that is backwards compatible as well?
Paul.
More information about the core-libs-dev
mailing list