I'll never get used to this... ever:
public enum STUPID { alpha, beta, gamma }
Where this...
switch(myStupid) { case STUPID.alpha: break; case STUPID.beta: break; case STUPID.gamma: break; }
Will give you this: "The enum constant STUPID.alpha reference cannot be qualified in a case label".
"The enum constant STUPID.alpha reference cannot be qualified in a case label"
Just remove the qualifier, STUPID:
STUPID
switch(myStupid) { case alpha: break; case beta: break; case gamma: break; }
Not very helpful when you're using Intellisense to complete your case statements and it just seems to be one of those things I forget almost every single time.
Erik
Tuesday, July 29, 2008 10:35 AM
Can you figure out the reasoning behind this? Because I can't. It seems like allowing, or even requiring qualifiers in this case would be the right thing to do.
Dave
Wednesday, July 30, 2008 8:24 PM
Erik, you're brilliant, insightful and absolutely right. There doesn't appear to be any logical reasoning especially considering other languages (C# for example) use the qualifier. I very, very briefly tried to find an explanation for this and didn't have any luck. My best guess it's an oversight or laziness.
Jerome
Sunday, August 03, 2008 5:15 AM
Dave, thanks for the help, I just found this situation and appreciated your confirmation of something unexpected. However, I agree there is a good reason to not provide the type, as explained here: bugs.sun.com/.../view_bug.do?bug_id=6191812 (Java cases values cannot be from any enum type except the enum type of the selector, to avoid comparing values of different enums. Hence... I must agree there is reason to be required / allowed to specify the enum type multiple times. Right?)
Sunday, August 03, 2008 8:20 PM
Thanks Jerome. The bottom line, for me: This is strictly a matter of compile-time, convenience for the developer, and there's no convincing evidence provided for NOT allowing this convenience. Judging the traffic to this post, I'll bet there's many more developers Googling away trying to understand an un-intuitive implementation to something that would appear to be quite natural. I understand the argument that, "if it can't be anything else, why qualify it." I just want to be able to use my intellisense to list my choices in a very intuitive way... just like other languages, like C#.
g1Port.com
Sunday, December 14, 2008 7:07 PM
It should be more than being oversight or laziness since I've faced same thing while writing for Android, a different VM. Really interesting. Anyway. Helped a lot. Many thanks. Merry Christmas!
Sascha
Thursday, January 08, 2009 6:58 AM
Thanks a lot! Really needed that info
Jenga
Sunday, February 22, 2009 7:16 PM
Many thanks. Regards, Jenga.
Jim
Thursday, June 25, 2009 3:41 PM
Thanks, this was helpful, Jim
Saturday, July 04, 2009 2:53 PM