I need to use lambdas to generate some lists of new objects. These new objects inherit some of the traits from the existing ones. Since it's hard to describe it without going into too much delicate details, I'll use an example of a parent and their children.
I want to generate a list of kids based on a list of people (one person = one kid). Kids should inherit only some traits of their parents (in this case, let's say it's a skin colour).
Since I'm somewhat forced to use lambdas (but also want to learn how it works), I've tried the following solution but I can't get over the problem with correct mapping (haven't seen anything like that yet and I'm doing a trial&error method). Probably I have a badly made constructor as well.
public class Kid {
private Colour colour;
private Person person;
public Kid(Person person) {
this.colour = person.getColour();
}
public List<Kid> listOfKids() {
return people.stream()
.map(e -> new Kid(e));
}
}