Bug in switch around Enums?

Tom Ball Tom.Ball at Sun.COM
Sat Sep 29 08:10:24 PDT 2007


Okay, it's not a bug since the spec says its not.  It is still an 
unnecessary syntactic inconsistency between constants and enums, 
however, and inconsistencies like this making the language a little 
harder to learn (yet another rule to remember).  This can't be changed 
in the compiler until the spec is, but perhaps there is a related 
pending JSR which can add it as an update.

Tom

Matthias Ernst wrote:
> Ted,
> 
> according to the JLS it's not a bug.
> 
> Switch labels can either be constant expressions or enum identifiers:
> 
> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.11
> SwitchLabel:
>        case ConstantExpression :
>        case EnumConstantName :
>        default :
> 
> and constant expression is only defined for primitives and String:
> http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.28
> 
> So (STAGGER) is neither a constant expression nor an enum constant name.
> 
> Feel free to call me type 1
> (http://diveintomark.org/archives/2004/08/16/specs) :-)
> 
> Matthias




More information about the compiler-dev mailing list