Here's my scenario:
private List<Entity> getPlanets() {
return entities.values()
.stream()
.filter(x -> x instanceof Planet)
.collect(Collectors.toList());
}
Entityis the super class ofPlanet- entities is a
HashMap<Entity> - As the method is called "getPlanets" I would like it to return a
List<Planet>but it appears to me that the stream expression is going to return aList<Entity> - I tried some casting expressions but none seem to work out.
I am brand new with Java 8 streams so maybe someone can point out what I am missing?