Sealed type
A sealed type is a type whose declaration restricts which types may directly extend or implement it, limiting its hierarchy to permitted subtypes.
Data-Oriented Programming in Java
A sealed Java type restricts which classes or interfaces may directly extend or implement it.
- How it is used
- Models mutually exclusive domain alternatives and prevents unknown implementations from entering a closed family.
- How deep it goes
- Explains declarations, implicit permits, and OR semantics, while deferring the additional machinery behind set-based sum-type representations.
- Examples
- Uses checklist statuses and a Rule algebra containing Equals, And, Or, and Not.
- What you can do after
- Build it from scratch as a closed Java family whose permitted alternatives encode domain choices directly.
Read how Data-Oriented Programming in Java explains sealed type →
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.
Also covered in
- The Art of Code
- Clean Applications with Hexagonal ArchitectureIn early access (MEAP)
What to know first
- algebraic data typeAn algebraic data type is a composite type whose values are formed from product structures, finite alternatives, or both through type constructors.
- recordA record is a structured representation of related fields or components, either as one data entry or as a type defining such entries.
Related concepts
- union typeimplements · A union type is a type whose values can represent one of several specified alternative types or variants.
- natural language interfacekind of · A natural language interface enables interaction with a system through human-language text or speech.
- class hierarchyconfigures · A class hierarchy is an organization of related classes connected by inheritance relationships, typically from more general base classes to more specialized derived classes.
- compileruses · A compiler is software that translates source code into another representation, such as machine code, bytecode, or an intermediate form.
- inheritanceconfigures · Inheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
Questions about sealed type
What is sealed type?
A sealed type is a type whose declaration restricts which types may directly extend or implement it, limiting its hierarchy to permitted subtypes.
Which Manning books explain sealed type?
Data-Oriented Programming in Java, 100 Java Mistakes and How to Avoid Them and Kotlin in Action, 2E.
What should I know before learning sealed type?
Manning books that teach sealed type usually introduce Java, algebraic data type and record first.
What is sealed type a kind of?
Sealed type is a kind of natural language interface. A natural language interface enables interaction with a system through human-language text or speech.
What is sealed type also called?
Sealed type is also called sealed hierarchy.
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.


