I would expected that both put operations throw a NullPointerException in the following code, but actually the lambda expression works fine while just the method reference throws a NPE.
public static void main(String... args) {
Object object = null;
Map<String, FuncInterface> map = new HashMap<>();
map.put("key1", () -> object.notify()); // works
map.put("key2", object::notify); // throws NPE
}
@FunctionalInterface
private interface FuncInterface {
public void someAction();
}
What is the difference?