liveBook · Manning

Sealed type

Also called sealed hierarchy

A sealed type is a type whose declaration restricts which types may directly extend or implement it, limiting its hierarchy to permitted subtypes.

How 3 Manning books explain it

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.

Read how Kotlin in Action, 2E explains sealed type →

Also covered in

What to know first

Related concepts

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.