permits Clause
List permitted subtypes.
The permits Clause
The permits clause is how a sealed type names its allowed subtypes. It comes right after the type name and the permits keyword.
Basic Syntax
List the permitted subtypes separated by commas after permits.
public class Main {
sealed interface Vehicle permits Car, Truck, Motorcycle {}
record Car() implements Vehicle {}
record Truck() implements Vehicle {}
record Motorcycle() implements Vehicle {}
public static void main(String[] args) {
Vehicle v = new Truck();
System.out.println(v.getClass().getSimpleName());
}
}