← Monday, October 19, 2026Languages & toolsGuide
Java sealed classes enable exhaustive pattern matching without a default case
The examples show sealed interfaces limiting permitted subtypes so a switch can handle every case without a default branch. This helps Java engineers make type changes easier to catch during compilation.
- What
- - Java sealed classes let developers explicitly list the permitted subtypes of an interface or base class.
- How
- - The compiler checks whether a switch covers every subtype; adding a subtype can break consumers that omit a case.
- Why it matters
- - For public APIs, adding a sealed subtype may require a major version bump; separately compiled consumers can instead fail at runtime.
Read on neilmadden.blog → Hacker News · 113 comments
Discussion
Discussion is not switched on yet. Use Note above to keep your own thoughts on this story.
Headline, summary, brief and diagram are written by a model from the source's own text; the link, byline and numbers come from the source. Read the original before relying on a claim.