Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Cant get switch statements working with enumerator.
Cant get switch statements working with enumerator. [message #200074] Mon, 04 April 2005 05:11 Go to next message
Eclipse UserFriend
Hi Guys...I've just downloaded 3.1 M6, and hoped the switch statement with
enums was working. It seems, if I trawl through the bug lists, people are
able to perform switch statements on enums. So what am I doing wrong?
Below, my code.

Cheers,
Martin

public class EnumTester {

public enum color {black, white}

public void test(color c) {
switch (c) {
case color.black:
System.out.println("Black");
break;
case color.white:
System.out.println("White");
break;
}
}
}
Re: Cant get switch statements working with enumerator. [message #200083 is a reply to message #200074] Mon, 04 April 2005 05:16 Go to previous messageGo to next message
Eclipse UserFriend
I forgot to mention, my workspace is set the compile with jdk 5.0, and the
exception I'm getting was:

The enum constant EnumTester.color.black reference cannot be qualified in
a case label

Cheers
Re: Cant get switch statements working with enumerator. [message #200099 is a reply to message #200083] Mon, 04 April 2005 06:22 Go to previous messageGo to next message
Eclipse UserFriend
Remove qualification as the compiler tells you. Simple names are required
there (as per JLS).
For some obscure reason, quite counter-intuitive, this unnecessary
constraint got added to Java 5. Blame the spec <g>

"Martin Coetzee" <martin@coetzee-family.com> wrote in message
news:9be6f695563ab6be9213bfa47d6db1fc$1@www.eclipse.org...
> I forgot to mention, my workspace is set the compile with jdk 5.0, and the
> exception I'm getting was:
>
> The enum constant EnumTester.color.black reference cannot be qualified in
> a case label
>
> Cheers
>
>
Re: Cant get switch statements working with enumerator. [message #200123 is a reply to message #200099] Mon, 04 April 2005 08:40 Go to previous messageGo to next message
Eclipse UserFriend
Thanx Philippe. Was just weird the way the code is formulated. Got it
working, thanx.

Regards,
Martin Coetzee (South Africa)
Re: Cant get switch statements working with enumerator. [message #200197 is a reply to message #200123] Tue, 05 April 2005 05:44 Go to previous messageGo to next message
Eclipse UserFriend
Feel free to suggest a better error message, that we control.

"Martin Coetzee" <martin@coetzee-family.com> wrote in message
news:2c8a62ade1ca6708e8467f5d936242ef$1@www.eclipse.org...
> Thanx Philippe. Was just weird the way the code is formulated. Got it
> working, thanx.
>
> Regards,
> Martin Coetzee (South Africa)
>
Re: Cant get switch statements working with enumerator. [message #200228 is a reply to message #200197] Tue, 05 April 2005 06:39 Go to previous message
Eclipse UserFriend
FYI: I filed enhancement request
https://bugs.eclipse.org/bugs/show_bug.cgi?id=90140
for a quick fix for this.

Markus

Philippe Mulet wrote:
> Feel free to suggest a better error message, that we control.
>
> "Martin Coetzee" <martin@coetzee-family.com> wrote in message
> news:2c8a62ade1ca6708e8467f5d936242ef$1@www.eclipse.org...
>
>>Thanx Philippe. Was just weird the way the code is formulated. Got it
>>working, thanx.
>>
>>Regards,
>>Martin Coetzee (South Africa)
Previous Topic:Scroll wheel not working in custom editor
Next Topic:macos x java app debugged with eclipse can't find native libraries
Goto Forum:
  


Current Time: Sat Jun 07 17:40:59 EDT 2025

Powered by FUDForum. Page generated in 0.03072 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top