This is to avoid the ability to compare against different enum types. It makes sense to restrict it to one type, i.e. the type of the enum value in the switch
statement.
Update: it's actually to keep binary compatibility. Here's a cite from about halfway chapter 13.4.9 of JLS:
One reason for requiring inlining of constants is that switch
statements require constants on each case
, and no two such constant values may be the same. The compiler checks for duplicate constant values in a switch
statement at compile time; the class
file format does not do symbolic linkage of case values.
In other words, because of the class identifier in EnumType.ENUM1
, it cannot be represented as a compiletime constant expression, while it is required by the switch
statement.