Reputation: 5371
I'm on jre7 and I still can't switch on Strings. I installed jdk7 update 1 and pointed Eclipse to it but still no luck. Any idea what I'm doing wrong?
Here is a the code:
String code = "something";
switch(code) {
case "xxx": dosomehting(); break;
default: dosomethingelse(); break;
}
The error I get:
Cannot switch on a value of type String. Only convertible int values or enum constants are permitted.
Upvotes: 3
Views: 12118
Reputation: 5545
I am pretty sure that Eclipse 3.7 only support jdk 1.6. You need 3.7.1 according to http://download.eclipse.org/eclipse/downloads/drops/R-3.7.1-201109091335/index.php
(Remember: Eclipse don't use suns compiler, they use their own, so installing jdk 1.7 is not enough).
Just open eclipse and select help->Check for updates. - That should upgrade you to 3.7.1
Upvotes: 2
Reputation: 72294
Three things spring to mind to check:
Upvotes: 0
Reputation: 14234
It sounds like you're still trying to compile under the old JDK [6 or earlier] Install the JDK, and make sure your Eclipse settings reflect the new platform. Additionally check if your project is reflecting the JDK7 platform.
Upvotes: 1