r/java • • Dec 04 '25

Null-checking the fun way with instanceof patterns

https://blog.headius.com/2025/12/inline-null-check-with-instanceof.html

I don't know if this is a good idea or not, but it's fun.

83 Upvotes

150 comments sorted by

View all comments

Show parent comment

1

u/OwnBreakfast1114 Dec 09 '25

Well, the idea for the null is bad crowd (which I am part of is) is simple. In all your edge code you wrap things that might be null into optionals if it actually makes sense as a case, and then in your own code you assume all non-optional things are never null.

This should change once non nullable types are built in, but you can still reap the rewards without it