Using qualified enum in `old` switch
David Alayachew
davidalayachew at gmail.com
Mon Jul 10 13:31:27 UTC 2023
CC'ing the Amber Dev Team.
On Mon, Jul 10, 2023 at 4:21 AM Mikhail Pyltsin <pyltsinm at gmail.com> wrote:
> 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?
>
> This question arose because the next code doesn't produce errors:
> ```
> enum EN{A, B}
>
> public void test(EN en) {
> switch (en) {
> case A -> System.out.println("a");
> case EN.A -> System.out.println("a too");
> case EN.B -> System.out.println("b");
> }
> }
> ```
> Is this expected?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230710/16ea4eaa/attachment-0001.htm>
More information about the amber-dev
mailing list