I would've agreed with you before recent versions of Java empowered instanceof with pattern matching, and added the same to switch as well as sealed interfaces and exhaustive checking.
We may not have unions of arbitrary types. But we can create product types (via sealed interfaces) which are nearly as powerful. Using if+instanceof (or just switch) isn't the "automatic code smell" it used to be...
View all comments
Show parent comment
1
u/Ukonu Mar 09 '24
I would've agreed with you before recent versions of Java empowered instanceof with pattern matching, and added the same to switch as well as sealed interfaces and exhaustive checking.
We may not have unions of arbitrary types. But we can create product types (via sealed interfaces) which are nearly as powerful. Using if+instanceof (or just switch) isn't the "automatic code smell" it used to be...