5

What is the right behavior according to JLS when methodReferenceOfNullObject() is invoked?

  • throw a NullPointerException (Oracle Java Compiler) or
  • assign supplier to result though o is null (Eclipse Java Compiler)

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

0 Answers0