Is it possible to cast a stream in Java 8? Say I have a list of objects, I can do something like this to filter out all the additional objects:
Stream.of(obj
Late to the party, but I think it is a useful answer.
flatMap would be the shortest way to do it.
Stream.of(objects).flatMap(o->(o instanceof Client)?Stream.of((Client)o):Stream.empty())
If o is a Client then create a Stream with a single element, otherwise use the empty stream. These streams will then be flattened into a Stream.