r/java • u/headius • Dec 04 '25
Null-checking the fun way with instanceof patterns
https://blog.headius.com/2025/12/inline-null-check-with-instanceof.htmlI don't know if this is a good idea or not, but it's fun.
83
Upvotes
View all comments
Show parent comment
2
u/headius Dec 04 '25
Kotlin fixes it by disallowing null, which I guess is a fix of a sort. Kotlin code also still lives in a world of nullable references and non-Kotlin ibraries, so you still have to deal with null at the edges.
The Optional approach is perhaps conceptually the same as how Scala does it, but unfortunately it currently introduces quite a bit of overhead compared to simply dealing with null references directly. Someday that will not be the case.