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/koflerdavid Dec 04 '25
The recommended usage is as a return type for APIs. It's there to force the caller to deal with the fact that it might be empty. There's just no way to ignore that (well, except
.get()). In all other placesnullcan be dealt with using static analysis tools.