sealed type

A class or interface that lists exactly which types may extend or implement it, so the compiler knows the complete family.

In more detail

The permits clause names the direct subtypes, and each must declare itself final, sealed or non-sealed. Because the family is closed, a switch over it can be exhaustive with no default branch, and adding a new subtype makes the compiler point at every switch that must handle it. Sealed types have been standard since Java 17.

Example

public sealed interface PaymentResult permits Approved, Declined, Pending { }

Related terms

Taught in

References

Certification courses