3 ms·
I wish and hope that, in some future version of the Java language, they will change the behavior of Java references so that they are explicitly non-null by defa
by jcrites 8y ago
I wish and hope that, in some future version of the Java language, they will change the behavior of Java references so that they are explicitly non-null by default, and require an annotation or signifier of some kind to mark them as nullable.
The Kotlin language (JVM-based) got this right: https://kotlinlang.org/docs/reference/null-safety.html https://kotlinlang.org/docs/reference/null-safety.html
In the meantime, Java coding best practices dictate treating all references as non-null in first-party code (defensively checking references received from third-party code, such as with Objects.requireNonNull), and avoiding nullable references in favor of Optional.
- staticassertion 8y agoThis won't happen. But Java is likely to get value types, which would be non-null just as in other languages with value types. The issue of Optional<T> being nullable is an extremely uncommon one - I have seen it happen once ever, and there were way bigger issues going on that happened to manifest that way. It's one of those "that's dumb but ultimately makes no difference" problems that many languages have.