source isn't updating with new JDK

I recently installed IntelliJ so I'm still really new to it. When I installed it I had JDK 1.6 (x86) installed. But I ran into issue when compiling some code that had a switch statement with a string as it's only valid in JDK 7+.

So I installed JDK 1.7 (x64), chose it as a project sdk, and tried to compile the same code but got this error.

Error:(39, 15) java: strings in switch are not supported in -source 1.6
  (use -source 7 or higher to enable strings in switch)

I then installed JDK 1.8 (x64), chose it as a the project sdk, and tried to compile the same code. Still received the same error.

Here's the Path envieronment variable.

C:\ProgramData\Oracle\Java\javapath;

Here's the java version from the command line

command line> java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Any idea how to fix my compile error?

6 comments
Comment actions Permalink

Hello.

Path environment variable and java version from the command line are most likely not involved.

Open Project Structure dialog, Modules section. Select the problematic module. Check Sources tab, "Language level" combobox. The level should be not less than 7.

If this combobox specifies "Use project language level" then chek that project level in the Project section of the very same dialog.

Don't hesitate to comment in case of problems.

Regards,
Alexander.

0
Comment actions Permalink

Thanks, that was exactly what I needed. I wasn't aware of the "Project Strucure" option yet.

Should the "Language Level" be the same as the "Project SDK" level? IE) Should JDK 8 uses Language Level 8 or is it fine to use Language Level 9?

0
Comment actions Permalink

In general, user may want to use newer JDK, but keep the source code compatible with older one. For any reason, e.g. to keep ability to build the project with older compiler too.

Regards,
Alexander.

0
Comment actions Permalink

So that means Language Level <= JDK version?

Can the Language Level ever be higher than the JDK version?

ex) Language Level 9 with JDK 7 or 8

0
Comment actions Permalink

Practically Language Level should really be not greater than JDK version. But UI allows to set any value, just to avoid superfluous limitations.

Regards,
Alexander.

0
Comment actions Permalink

Thank you for all your help!

0

Please sign in to leave a comment.