I am using Eclipse to develop a Java program. I had to downgrade JRE and JDK from 1.7x to 1.6. Now everything is pointing to 1.6.x (including the installed JRE and JDK compliance).
But now Eclipse still gives me an error on the switch
statement, indicating:
Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted
on the code below:
Switch("test") // Which is fine with 1.7.x
I removed 1.7.x from computer, not sure why it is still looking for 1.7 instead of 1.6?
Switching on strings was introduced in Java 1.7!
The error message is expected when you downgrade to Java 1.6. In that version you can only switch on primitive types and enums.
Related question:
Right click on your project, go to Properties. Select Java Compiler from the left menu. Select your compliance level (1.7 or 1.6). 1.7 will stop that message. 1.6, as others said before, won't let you use strings.
Actually, your code is not valid on 1.6. You can't do a switch on a String.
switch(String)
is syntax applicable from Java 7 onwards. Because you have 1.6 which doesn't support switch(String), eclipse giving compilation error.
Change switch(String)
to switch(int)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With