Qualified enum constants in switch?

Gavin Bierman gavin.bierman at oracle.com
Wed Jul 12 22:06:17 UTC 2023


Yes, they are allowed - we just tweaked the language in the spec.

Gavin

> On 6 Jul 2023, at 09:20, Tagir Valeev <amaembo at gmail.com> wrote:
> 
> Hello!
> 
> We are working on Java 21 support in our IDE, and stumbled the following issue.
> Previous draft of spec [1] said:
> 
> Every case constant must be either (1) the null literal, (2) a
> constant expression (15.29), or (3) the (simple or qualified) name of
> an enum constant (8.9.1); otherwise a compile-time error occurs. A
> single null case constant may also be paired with the default keyword.
> 
> Now, it says [2]
> 
> Every case constant must be either a constant expression (15.29), or
> the name of an enum constant (8.9.1), or a compile-time error occurs.
> 
> So, now it doesn't mention the qualified names. Still JEP 441 [3]
> still mentions that qualified enum constants are allowed. Could you
> please tell me whether the intent is to keep this part of
> specification, or it was decided to drop it?
> 
> With best regards,
> Tagir Valeev.
> 
> [1] https://cr.openjdk.org/~gbierman/jep440+441/jep440+441-20230524/specs/patterns-switch-record-patterns-jls.html
> [2] https://cr.openjdk.org/~gbierman/jep440%2B441/jep440+441-20230612/specs/patterns-switch-record-patterns-jls.html
> [3] https://openjdk.org/jeps/441



More information about the amber-spec-experts mailing list