Sealed type
A sealed type is a class or interface that restricts which other types may directly extend or implement it to a permitted set.
100 Java Mistakes and How to Avoid Them
A sealed interface is a Java interface that restricts which classes or interfaces may directly implement or extend it.
- How it is used
- Uses a closed Entry hierarchy to make list processing exhaustive at compile time.
- How deep it goes
- Defines a sealed interface hierarchy and demonstrates compiler-checked exhaustive switching, without detailing broader hierarchy design.
- Examples
- Uses Entry with IntEntry and StringEntry records to process a list through an exhaustive switch.
- What you can do after
- Apply via the Java 21 compiler to force handling of newly added inheritors.
Read how 100 Java Mistakes and How to Avoid Them explains sealed type →
Kotlin in Action, 2E
A sealed interface is a Kotlin interface whose implementations are restricted to a known set once its containing module is compiled.
- How it is used
- Restricts interface implementations so closed hierarchies can be handled exhaustively with when expressions.
- How deep it goes
- Explains module-level implementation restrictions and compiler exhaustiveness, stopping short of broader hierarchy mechanics.
- Examples
- Uses Toggleable with LightSwitch and Camera, alongside expression hierarchies demonstrating exhaustive evaluation.
- What you can do after
- Build it from scratch by declaring a sealed interface, implementing it, and relying on compiler-checked exhaustive when handling.
Related concepts
- natural language interfacekind of · A natural language interface enables interaction with a system through human-language text or speech.
- union typeimplements · A union type is a type whose values can be any one of several specified alternative types or variants.
- compileruses · A compiler is software that translates source code into executable code or another representation, while analyzing it according to the source language’s rules.
- HTTP response codeproduces · An HTTP status code is a standardized three-digit value in an HTTP response that indicates the outcome of processing the corresponding request.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

