【发布时间】:2018-06-13 11:28:34
【问题描述】:
java 8中map方法的语法是:
<R> Stream<R> map(Function<? super T,? extends R> mapper)
但我可以使用 lambda 表达式:
personList.stream().filter(p -> p.getPersonType().equals("student"))
.map(p -> new Student(p.getId(), p.getName()))
.collect(Collectors.toList());
map 方法中的参数如何等同于 Function 数据类型。请帮助我理解这一点。
谢谢
【问题讨论】:
-
你可以这样写
Function<Person,Person> function = p -> new Student(p.getId(), p.getName())