Java sealed classes and exhaustive pattern matching
Summary
Java 17 introduced sealed classes to restrict subtypes, enabling exhaustive pattern matching and compile-time checks for switches. The article explains how sealed types can cause runtime breakage if new subtypes are added without recompiling dependents, and discusses API-design considerations. It includes code examples and guidance on when to use sealed types, especially inside components rather than across public APIs.