How to make IntellijIDEA work with Java 12

Lapo :

I haven't used Java for quite some time, and today I wanted to re-start using it. So I updated my IDE (IntellijIDEA) to 2019.1.3 version1, and I downloaded Java 12. Then I proceeded to uninstall my old Java 8 (and I deleted the folder with the SDK of Java 8 from my PC with Windows 10).

Then I opened IntellijIDEA, File -> Project Structure... -> Project -> Edit (Project SDK) and there I selected the folder where I had just installed Java 12 (C:\Program Files\Java\jdk-12.0.1). In the same window where I edited the SDK I set Project language level to 12 - no new language features.

Then I went to File -> Project structure -> Modules -> Dependencies and I checked that Module SDK switched to 12 - no new language features. And indeed it did.

I clicked on Apply and then OK.

Then I went to File -> Settings... -> Build, Execution, Deployment -> Compiler -> Java Compiler and I set Project bytecode version to 12.

I clicked on Apply and then OK.

I closed IntellijIDEA and shut down my PC. Then I turned my PC back on, I re-opened IntellijIDEA, I typed var and IntellijIDEA told me: Cannot resolve symbol 'var'.

I've found a lot of people with my issue by searching on Google, but none of them actually managed to resolve my problem. Here there are some question on Stack Overflow I've already read:


1

IntelliJ IDEA 2019.1.3 (Community Edition)

Build #IC-191.7479.19, built on May 28, 2019

JRE: 1.8.0_202-release-1483-b58 amd64

JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Windows 10 10.0

Lapo :

Ok, the problem was that I'm lazy and that, in my humble opinion, the error message displayed by IntellijIDEA isn't very accurate.

I tried to build the project, and in the log I get a different error message: Java 'var' is not allowed here.

Of course var isn't allowed to infer the type to a class field, but when I tryed it in a method, all is fine.

My fault, I wanted to check very fast if the switch to Java 12 has occured and I didn't think I couldn't use that construct in that place. By the way IntellijIDEA should have immediately showed me the "accurate" reason of the issue.

I should have been more careful, thanks a lot to @TituBG, @JacobG. and @VinceEmigh for their time!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=123378&siteId=1