Additional method on Stream

Stephen Colebourne scolebourne at
Mon Apr 27 13:22:49 UTC 2015

This is a request for an additional method on

Having written quite a bit of code in Java 8 now, one annoyance keeps
on coming up, filtering and casting the stream.

Currently, it is necessary to do this:



        .filter(t -> t instanceof Foo)
        .map(t -> (Foo) t)

Really, what is needed is this:


For info, Guava's FluentIterable has such a method.

The new method signature would be something like:

public Stream<R> filter(Class<R> cls);

As far as I can see, there is no problem in implementing this in both
serial and parallel modes, as it is essentially just a convenience.


More information about the core-libs-dev mailing list