Whilst debugging my code, I came across this interesting scenario with my switch statement on an enumeration.
To me it looks like it should not compile and prevented me from making the silly mistake, is there something I am missing where this syntax can be used?
My java version is 1.6.0_10
private enum E_TEST
{
A, B, C, D, E
}
public static void main( String[] args )
{
for( E_TEST e : E_TEST.values() )
{
switch( e )
{
case A: B: C: D: E:
{
System.out.println( e );
break;
}
}
}
}
For completeness, the output of this code is as follows.
A
The code compiles because in the line
the B:, C:, D: and E: are labels.
It doesn’t do what you expect because that line should be
as dasblinkenlight noted in his post.