Sealed types

A sealed class or interface (sealed) restricts the list of its subtypes with permits. Subtypes must be final, sealed, or non-sealed. Combined with pattern matching in a switch, it lets the compiler verify that all cases are handled, without a default.

Example

sealed interface Forme permits Cercle, Carre {}

Related concepts

The whole glossary