Sealed and Enum Classes

Sealed Classes, Enum Classes and Pattern Matching

The data classes of Classes and Data Classes describe one shape of data. Apps also need closed sets: a sort order, a cart action, a screen that is loading, loaded or failed. An enum class is a fixed list of instances; a sealed class or interface is a fixed list of types. With when, both let the compiler prove you handled every case.

Subsections