/** Enums with pattern-matching switch (final in 21): an enum implementing a sealed interface, qualified constants, and exhaustiveness. */
public class EnumPatterns {
    sealed interface Token permits Keyword, Number {}
    enum Keyword implements Token { IF, ELSE, WHILE }
    record Number(int value) implements Token {}

    static String describe(Token t) {
        return switch (t) {                       // no default: Keyword (all constants) and Number cover the sealed type
            case Keyword.IF -> "the if keyword";
            case Keyword k -> "another keyword: " + k.name().toLowerCase();
            case Number(int v) when v < 0 -> "negative number " + v;
            case Number(int v) -> "number " + v;
        };
    }
    public static void main(String[] args) {
        for (Token t : new Token[] { Keyword.IF, Keyword.WHILE, new Number(-3), new Number(8) }) System.out.println(describe(t));
    }
}
