Core concept
sealed interface Shape permits Circle, Rect {}
record Circle(double r) implements Shape {}
record Rect(double w, double h) implements Shape {}Advertisement
How it works
All permitted classes in same module/package for compilation.
Advertisement
Trade-offs + gotchas
Modeling closed hierarchies (ADTs). Type-safe state machines.