Java stream API:恒等函子有语法糖吗?

Java stream API: are there syntax sugar for identity functor?

我们使用几个 Map 作为对象列表的简单内存数据库:

class Person {
    public String id;
    public String phone;
    public String email;
    // and get/set and other fields...
}

List<Person> persons;
Map<String, Person> emailLookup = persons.stream()
        .collect(Collectors.toMap(Person::getEmail, p -> p));
Map<String, Person> phoneLookup = persons.stream()
        .collect(Collectors.toMap(Person::getPhone, p -> p));
Map<String, Person> idLookup = persons.stream()
        .collect(Collectors.toMap(Person::getId, p -> p));

Java SE 中是否有任何语法糖或内置仿函数来用其他东西替换 p -> p

您可以使用 Function.identity(),但如果您想要短一点,那么我认为您不会超过现有的 p -> p