I found that function interface and getMethod seem to be replaceable, What makes it work?
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"));
}
public String getString() {
return "str";
}
}
But when I use lambda to replace getMethod, it fails . Why this does not work
Map<String, String> collect = Stream.of(new App(), new App(), new App())
.collect(Collectors.toMap(() -> "str", (app) -> "aaa"));