我们有一个Map<String, Student> studentMap
,其中Student
是以下类:
class Student{
String name;
int age;
}
我们需要返回一个所有年龄大于20的
eligibleStudents
的ID列表。为什么以下代码会在Collectors.toList
处出现编译错误?HashMap<String, Student> studentMap = getStudentMap();
eligibleStudents = studentMap .entrySet().stream()
.filter(a -> a.getValue().getAge() > 20)
.collect(Collectors.toList(Entry::getKey));