Here's my scenario:
private List<Entity> getPlanets() {
return entities.values()
.stream()
.filter(x -> x instanceof Planet)
.collect(Collectors.toList());
}
Entity
is the super class of Planet
HashMap<Entity>
List<Planet>
but it appears to me that the stream expression is going to return a List<Entity>
I am brand new with Java 8 streams so maybe someone can point out what I am missing?
return entities.values()
.stream()
.filter(x -> x instanceof Planet)
.map(x -> (Planet) x)
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With