I am trying to build a simple program that demonstrate the use of the String class being evaluated in a switch statement but i'm getting a compilation error because this feature requires Java SE 7 (whish is installed in my computer).
Error message on line 5: Cannot switch on a value of type String. Only convertible int values or enum cons tants are permitted
Is Eclipse pointing at JRE7 ? = YES . Is Environnement variable Pointing at JDK7 =YES .
java -version = OK (see pict below).
I even tried to compile the code with the console prompt. See error:
import javax.swing.JOptionPane;
public class SwitchDemo {
public static void main(String[] args) {
String name = "georges";
switch (name.toLowerCase()) {
case "Jhon":
JOptionPane.showMessageDialog(null, "Good morning, Jhon!");
break;
case "georges":
JOptionPane.showMessageDialog(null, "How's it going, georges?");
break;
case "sergei":
JOptionPane.showMessageDialog(null, "sergei, my old sergei!");
break;
case "Steph":
JOptionPane.showMessageDialog(null, "Afternoon lennert, how's the Steph?");
break;
default:
JOptionPane.showMessageDialog(null, "Pleased to meet you, xxxxxx.");
break;
}
}
}