I am using stream to iterate through the list and want to collect it in the map but getting compile time error:
Method reference expression is not expected here
Here is my code
List<Person> personList = getPersons();
Map<String, Integer> personAgeMap = personList.stream()
.collect(Collectors.toMap(Person::getFirstName + "_" + Person::getLastName, Person::getAge));
I have checked these answers:
but these are not what i am looking for, also i have seen the method reference type.
In this case it is instance method of instance type, how can i have instance of Person in the collectors.
what could be the possible solution or is it even doable this way?