这个问题在这里已经有了答案:
java 8 Collector<String, A, R> is not a functional interface, who can tell why?
(2 个回答)
Java8: Using Function::identity in Collectors.toMap(..) creates an argument mismatch error
(1 个回答)
3年前关闭。
通常在 flatMap
之后,我们使用 collect(Collectors.toList())
收集数据并返回 List
.
但是为什么我不能使用 Collectors::toList
反而?我尝试使用它,但出现编译错误。
我试图搜索这个,但找不到任何解释。
非常感谢。
最佳答案
请参阅@Eran 的回答,因为它比我的更详细,但是如果有人想要 简单 解释:
你不能改变:collect(Collectors.toList())
至 collect(Collectors::toList)
你只能改变:collect(() -> Collectors.toList())
至 collect(Collectors::toList)
关于java - 为什么我在 Java 8 Lambda 中使用 "Collectors.toList()"而不是 "Collectors::toList"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51132863/