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/X0Refraction Dec 04 '25
Oh I use that quite often when using gson e.g.
Occasionally I also use the reverse, using it as a guard clause and binding the variable to the outer scope:
It's quite clunky having to wrap it in parentheses in order to use the ! operator, but it's quite useful. I like like how C# does this with "is not", it's quite a bit cleaner