Q on Patterns and Streams

Kasper Nielsen kasperni at gmail.com
Wed Jan 20 10:20:24 UTC 2021


On Wed, 20 Jan 2021 at 00:31, Johannes Kuhn <info at j-kuhn.de> wrote:
>
> Turns out I sometimes write code that looks like this:
>
>      foos.stream().filter(e -> e instanceof Foo).map(e -> (Foo) e)...
>
> or
>
>      foos.stream().filter(Foo.class::isInstance).map(Foo.class::cast)...
>
> Nicolas Fränkel has even written a blog post about this[1].

Now, this is a bit off-topic and I don't want to hijack your question.
But I've always wished Stream<T> had a
  <S> Stream<S> filterOnType(Class<? extends S> type);
method.

/Kasper


More information about the amber-dev mailing list