Java sealed classes enable exhaustiveness checking in switch expressions, letting the compiler verify all subtypes are handled without a default clause. However, there's a critical caveat: if a sealed type gains a new subtype and consumers aren't recompiled, a runtime MatchException is thrown instead of a compile-time error. This makes sealed types most valuable for internal component use where everything is recompiled together, but potentially problematic in public APIs — adding a new subtype becomes a breaking change that may only surface at runtime for consumers using older compiled code.
Sort: