4 ms·
The Java compiler “sucks” (not the language) because it’s not making optimisations that are safe and a human could do themselves fairly simply.
by pharmakom 4y ago
The Java compiler “sucks” (not the language) because it’s not making optimisations that are safe and a human could do themselves fairly simply.
- sshine 4y agoThe 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)
- masklinn 4y agoThat’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.