Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The Java compiler “sucks” (not the language) because it’s not making optimisations that are safe and a human could do themselves fairly simply.


The lack of optimisation here isn’t a dealbreaker. The fact that Optional<T> can also be null, because it’s a reference type, makes it a less safe implementation of optionals. That’s why the newer standard library uses static methods in a lot of places, e.g.:

  Optional.ofNullable(theField)


That’s just a convenience for

    theField == null ? Optional.empty() : Optional.of(theField);
As Optional.of will raise an NPE if given a null value.

It doesn’t change the issue that the Optional itself can be null, and that null is its default value.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: