调用methodReferenceOfNullObject()
时,根据JLS的正确行为是什么?
NullPointerException
(Oracle Java编译器)或将供应商分配给result
虽然o
是null
(Eclipse Java编译器)
public void methodReferenceOfNullObject() {
Object o = nullReference();
Supplier<String> result = o::toString; // <-- point of interest
...
}
private Object nullReference() {
return null;
}