Switch case using Strings

Hello,

I have a problem with switch cases in IntelliJ. Since 1.7 Java supports switch case using Strings.
In IntelliJ the compiler tells me " Incompatible types. Found 'Java.lang.String', required: 'byte, char, short or int' ".
In eclipse is everything working properly. I reinstalled all my JRE and JDK, also tried Java 8 Early Access. I'm using IntelliJ 12.1, but I also tried IntelliJ 13 EA. But always the same problem with switch case.

Code:

String s = "test";
switch (s) {
     case "test" : System.out.println("test");
}

Thanks in advance!

2 comments

If you are using regular Java module:
1. File > Project Structure...
2. Switch Project language level to 7.0 (Project Settings | Project).
If you are using Maven you need to change <source> and <target> respectively in maven-compiler-plugin configuration.

0

Please sign in to leave a comment.