Stream + BaseStream

Paul Sandoz paul.sandoz at
Tue Dec 17 00:42:39 PST 2013

On Dec 16, 2013, at 11:23 PM, Kasper Nielsen <kasperni at> wrote:

> Hi,
> IntStream/LongStream/DoubleStream all override
> sequential(), parallel(), unordered(), ... from BaseStream.
> However Stream does not override this methods

It does:

  public interface Stream<T> extends BaseStream<T, Stream<T>>

> so you have to cast the
> stream if you are you a using a non-parameterized stream, as in:
> Stream s = *null*;
> s = (Stream) s.unordered();

Because a raw-typed Stream is used, and therefore a raw type for BaseStream, the compiler cannot infer S and has to resort to using the upper bound, BaseStream:

  public interface BaseStream<T, S extends BaseStream<T, S>>

Using a raw type for Stream will also have other consequences for type inference when chaining operations. I have seen a number of examples highlighting issues (posted to various lists) that were in part broken because a raw type for Stream was used. I would recommend avoiding such use if at all possible.


More information about the lambda-libs-spec-observers mailing list