为什么 Java 的 Function 接口可以接收 getMethod 这种方法签名的,用 lambda 就不行呢
資深大佬 : ningmengmao 6
public class App { public static void main(String[] args) { Map<String, String> collect = Stream.of(new App(), new App(), new App()) .collect(Collectors.toMap(App::getString, (app) -> "aaa")); // Map<String, String> collect = Stream.of(new App(), new App(), new App()) // .collect(Collectors.toMap(() -> "str", (app) -> "aaa")); } public String getString() { return "str"; } }
我用方法引用可以编译运行,但是用 lambda 写法就不行了,这是为什么啊?
大佬有話說 (4)