Switch statement using a String with Java 1.7
Hi,
switch(name) //Where name is a String
{
Code block
}
I am trying to use a String switch statement like the one just above. I am getting the following error:
Error: Cannot switch on a value of type java.lang.String. Only convertible int values or enum constants are permitted.
After some research, a String can only be used in a switch statement in Java 1.7. I do have the most up to date version of Java 1.7 (checked on the java website) and I am still getting that error. Does anyone know why and how I can fix it?
Additional info: Compiler is Eclipse Compiler 0A48 with Dr. Java.
Thank you.
Re: Switch statement using a String with Java 1.7
From the wording of the error message it seems eclipse believes you wish to use an older version of java for that project.
I have encountered this error before and that was the cause of the issue for me. There is a way to tell eclipse to use a specific version by default, and a way to set the version per project. Unfortunately I do not remember how to make the change. Not much of an eclipse guy yet..
Perhaps some poking around on your own or with a search engine will help you determine if that is your problem or not.
Re: Switch statement using a String with Java 1.7
Right-click on your project and Open the project properties.
Then on the left menu, select Java Compiler. This will list the project-specific JDK compliance version that project is using.