'Java stream API: map field without getter syntax
class Person {
public String name;
public String getName() { return name; }
}
Are there special syntax sugar for accessing fields in stream API through lambda? I see:
List<Person> persons;
persons.stream().map(Person::getName).collect(Collectors.toList());
persons.stream().map(p -> p.name).collect(Collectors.toList());
What about something like (which is not working, I know that):
persons.stream().map(Person::name).collect(Collectors.toList());
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
