According to The Java Tutorials, in Java SE 7 and later, you can use a String object in the switch statement’s expression.
String s = ...
switch(s){
//do stuff
}
But is this true? I’ve installed the JRE and added it to the build path of my Eclipse project, but I’m getting the following compile-time error:
Cannot switch on a value of type
String. Only convertible int values or
enum constants are permitted
Also, I think I’ve got it configured correctly since I was able to use its java.nio.file.Files class, as well as JLayer.
Any ideas?
While it is true that the JDT team has implemented the Switch on String feature, the support for Java 7 won’t be before Eclipse 3.7.1:
See bug 288548: