null对象的实例方法引用

时间:2018-02-25 23:13:50

标签: java nullpointerexception java-8 method-reference ecj

调用methodReferenceOfNullObject()时,根据JLS的正确行为是什么?

  • 抛出NullPointerException(Oracle Java编译器)或
  • 将供应商分配给result虽然onull(Eclipse Java编译器)

    public void methodReferenceOfNullObject() {
        Object o = nullReference();
    
        Supplier<String> result = o::toString; // <-- point of interest
    
        ...
    }
    
    private Object nullReference() {
        return null;
    }
    

0 个答案:

没有答案