I was trying to create a method reference to an arbitrary object, so I defined the following types:
interface I {
boolean get(Impl impl);
}
static class Impl {
public boolean get() {
return true;
}
}
Then I declared the method reference, like below:
I i = Impl::get;
When I call:
i.get(null);
I get a NullPointerException:
Exception in thread "main" java.lang.NullPointerException
Can someone explain why this happens even though the Impl
reference is not used anywhere?