Using qualified enum in `old` switch

Mikhail Pyltsin pyltsinm at gmail.com
Sat Jul 8 14:20:15 UTC 2023


Hi!
I am investigating a new version of jep440+441
(
https://cr.openjdk.org/~gbierman/jep440%2B441/jep440+441-20230612/specs/patterns-switch-record-patterns-jls.html
)
After `2023-06-12: Misc editorial changes.` I can't find any explicit
mention that it is allowed to use qualified names for enums in `old` switch.
But according to https://openjdk.org/jeps/441 it must be allowed
```

static void goodEnumSwitch2(Coin c) {
    switch (c) {
        case HEADS -> {
            System.out.println("Heads");
        }
        case Coin.TAILS -> {    // Unnecessary qualification but allowed
            System.out.println("Tails");
        }
    }
}


```
before  `2023-06-12: Misc editorial changes.`, It was
```Every case constant must be either (1) the null literal, (2) a constant
expression (15.29
<https://docs.oracle.com/javase/specs/jls/se19/html/jls-15.html#jls-15.29>),
or (3) the (simple or qualified) name of an enum constant (8.9.1
<https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.9.1>);
otherwise a compile-time error occurs. A single null case constant may also
be paired with the default keyword.
```,  but now there is no mention of the type of enum names.

Could you help me, which point allows it now?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230708/0de2b0d5/attachment.htm>


More information about the amber-dev mailing list