/** Must NOT compile: the switch forgets Cod, and Payment is sealed, so the compiler knows. */ public class NonExhaustiveSwitch { sealed interface Payment permits Card, Upi, Cod {} record Card(String last4) implements Payment {} record Upi(String vpa) implements Payment {} record Cod() implements Payment {} static String describe(Payment p) { return switch (p) { case Card c -> "card " + c.last4(); case Upi u -> "UPI " + u.vpa(); }; } }