liveBook · Manning

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.

How 2 Manning books explain it

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 →

Related concepts

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.