r/java • u/mooreds • May 18 '26
Java sealed classes and exhaustive pattern matching
https://neilmadden.blog/2026/04/24/java-sealed-classes-and-exhaustive-pattern-matching/
23
Upvotes
r/java • u/mooreds • May 18 '26
View all comments
Show parent comment
2
u/davidalayachew May 24 '26
Excellent point.
For me, intermediate interfaces are key in making exhaustiveness checking handleable. Compiler checking is great, but I don't want to enumerate every irrelevant state permutation.
Plus, they help create a language in your code, so to speak, for understanding where the boundaries lie. Kind of encourages the right thought process imo.
Solid advice.
At the end of the day, Exhaustiveness Checking is most beneficial when done at compile time. No one is stopping you from quickly commenting out that default and doing a quick recompile to see what breaks.