您可以使用lambda:
Collectors.toMap(p -> p.getLast(), Function.identity())
或者,更简洁,您可以使用方法参考使用
:::
Collectors.toMap(Person::getLast, Function.identity())
而不是
Function.identity,您可以简单地使用等效的lambda:
Collectors.toMap(Person::getLast, p -> p)
如果使用Netbeans,则每当匿名类可以被lambda替换时,您都将获得提示。



