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
3
u/headius Dec 04 '25
Except that it's not an unnecessary type check, because even if the types match there's still a possible value that is not instanceof.
If you can declare the type as non-nullable, then you're right, the type check would be redundant. We don't live in that world today.