Is it possible to cast a stream in Java 8? Suppose I have a list of objects, I can do something like this to filter out all additional objects:
Stream.of(objects).filter(c -> c instanceof Client)
After this though, if I want to do something with the clients, I would have to launch each of them:
Stream.of(objects).filter(c -> c instanceof Client) .map(c -> ((Client) c).getID()).forEach(System.out::println);
It looks a bit ugly. Is it possible to broadcast an entire stream to a different type? Like the cast
Please ignore the fact that doing things like this would likely mean bad design. We do stuff like that in my computer class, so I was looking into the new features in Java 8 and was curious if this was possible.