Given the following entity:
public class Parent extends {
private Long id;
private List<Child> children = new ArrayList<>();
}
I am attempting to learn how to use the Java 8 Stream API to flatten a List<Parent>
, each containing a List<Child>
and pass the stream of Child
into a void method.
For example:
List<Parent> parents = //..
schedules.stream()
.flatMap(Parent::getChildren)
.forEach(this::invoke);
This gives the error:
Bad return type in method reference: cannot convert java.util.List< Child > to java.util.stream.Stream < ? extends R >