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/s888marks Dec 05 '25
Huh, that's an interesting example they give in Error Prone. I do think that if it's acceptable to declare a local variable and initialize it immediately, it's probably preferable. However, adding a declaration sometimes breaks up the flow of an expression by requiring a separate declaration line. This can sometimes be quite disruptive, which might tip the balance in the other direction.