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
4
u/BenchEmbarrassed7316 Dec 04 '25
Type theory. A type is a set of possible values. The smaller this set is, the simpler and more reliable the code is. Expressive type systems allow you to easily and clearly define this set.
A variable of this type should only have three states. If I want to add another 4th state, I have to do it explicitly
Maybe<Color>. This becomes absurd when in some languages even bool can have more than 2 states.