by rlawson · 2y ago · 0 comments
At some point I imagine they will have to remove or at least isolate and disarm some ubiquitous core features (e.g. serialisation and synchronisation).
JSR-305, checker framework, Optional are all half-baked workarounds evidenced by the lack of their adoption.
I can’t remember the last time I encountered one by using the proper compile time checks. It does need to be enforced organization-wide, and not partially with annotations, but if you can make that change then you can code in Java without the mental overhead of null.
> then you can pretty much eliminate NPE.
NPEs is only one kind of cost incurred by the lack of null safety. The other is all the unnecessary "if (x == null) {" boilerplate code caused by the uncertainty and defensive programming, which increases complexity and worsens readability.
When you're sufficiently careful, you can reduce accidental nulls down to the level of minor inconvenience.
But no amount of care on your part will stop your teammates from deliberately using nulls.
It's not. It's another half-feature into the collection of half-features mentioned in my post.
(This doesn't always work out, some bad API decisions[1] will likely haunt Java forever, some features are arguably a bit undercooked (e.g. exception handling in Stream:s), but given the constraints it's kind of remarkable how well it does work)
[1] https://stackoverflow.com/questions/21410683/boolean-getbool...
May be one day Java will just retire this concept and make all exceptions unchecked. It'll be backwards-compatible change. Make `throws` clause cause deprecation warnings and that's about it.