I have a list of Students which I want to convert into a Map<String, Integer>
, where the map key should be the first name of the student. To keep the code sample simple, I specified the map value as 1
:
final Map<String, Integer> map = someStudents.stream().collect(
Collectors.toMap(Student::getFirstName, 1));
The compiler complains about:
non-static method getFirstName() cannot be referenced from a static context
Any idea? I am confused because many examples use the same approach of passing a reference to the non-static method. Why does the compiler see a static context here?