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 写法就不行了,这是为什么啊?