Bug in switch around Enums?

Ted Neward ted at tedneward.com
Sat Sep 29 02:59:11 PDT 2007


A good friend of mine just stumped me with this one; forwarding here because
I believe it to be a bug in the compiler somewhere. Couldn’t remember if
Josh and Neal were on the list, so I added them in CC; sorry for the
duplication, guys.

 

Normally, case statements with or without parens around them will compile:

 

                int x = 0;

                switch (x) {

                        case (0): return "ZERO";

                        case 1 : return "ONE";

                }

 

But doing the same for Enum doesn’t compile when parens are there:

 

public class EnumTest

{

  public enum Test { WRAP, STAGGER, ROTATE, NONE };

  public static String toString(Test e) {

    switch (e) {

      //case (EnumTest.Test.STAGGER): return “STAGGER”;   // this will not
compile 

      case WRAP: return "WRAP";   // This, of course, is fine

      default: return "WTF?!?";

    }

  }

}

 

Is this a compiler/parser bug?

 

Ted Neward

Java, .NET, XML Services

Consulting, Teaching, Speaking, Writing

HYPERLINK "http://www.tedneward.com"http://www.tedneward.com

 


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.13.33/1034 - Release Date: 9/27/2007
5:00 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20070929/7764c8a3/attachment.html 


More information about the compiler-dev mailing list