Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 1.7 still telling me that strings in switch statements are incompatible

I'm using java 1.7 in intellij and it's giving me a compile error as if I'm using pre-1.7. Saying, "Incompatible type. Found 'java.lang.String'. required 'byte, char, short, or int'.

I'm rattling my brain trying to figure out why this is. Thanks

like image 244
Jpeppa Avatar asked Sep 10 '14 15:09

Jpeppa


2 Answers

You need to change language level in your IDE.

Check these settings:

  • File > Project Structure > Project > Project SDK
  • File > Project Structure > Project > Project Language Level
  • File > Project Structure > Modules > Your module > Sources > Language Level
  • File > Project Structure > Modules > Your module > Dependencies > Module SDK

Also check compiler settings. Sometimes it adds extra arguments to compiler:

  • File > Settings > Compiler > Java Compiler > Byte code version

If you use maven plugin enable auto-import. Then the language level will be detected automatically from your pom.xml settings.

like image 158
ponomandr Avatar answered Sep 24 '22 19:09

ponomandr


In your project settings most probably you use java compiler java 1.6 or prior. Change that to java 1.7

like image 34
AlexWien Avatar answered Sep 26 '22 19:09

AlexWien