3

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
  • 882
  • 1
  • 12
  • 28
  • 1
    Have you tried invalidating caches? – Vince Jul 12 '19 at 17:24
  • I hope you're not just typing `var` by itself, as it needs to be an expression for it to compile. What happens if you type `var test = "Hello World";` into your main method? – Jacob G. Jul 12 '19 at 17:24
  • @JacobG. Same issue. The problem is that the IDE doesn't recognize the symbol `var`. – Lapo Jul 12 '19 at 17:26
  • @VinceEmigh Yes, as statd in the third comment of [this question](https://stackoverflow.com/questions/49581032/local-variable-type-inference-not-being-recognized). – Lapo Jul 12 '19 at 17:27
  • 1
    I see. You listed your JRE as `1.8`. In Java 9+, the JRE is built into the JDK. Are you sure that you have Java 8 uninstalled entirely? – Jacob G. Jul 12 '19 at 17:27
  • @JacobG. Thanks for the answer. To uninstall Java 8 I uninstalled the "program" via Windows control panel. Then I deleted the folder where there was the SDK. What is weird is that when I instelled Java 12 (before uninstalling Java 8) it didn't ask me to remove older versions (as it usually does). – Lapo Jul 12 '19 at 17:31
  • As far as I know, Java 12 doesn't come with any installers. All you do is just drag the installed folder to your `Java` directory, and then set your PATH and JAVA_HOME. – Jacob G. Jul 12 '19 at 17:32
  • @JacobG. The JDK is a superset of the JRE - it has always had JRE capabilities, just with added development tools. – Vince Jul 12 '19 at 17:33
  • @JacobG. Actually I downloaded an installer when I downloaded Java 12. By the way I set those enviroment variables by following [this question](https://stackoverflow.com/questions/15796855/java-is-not-recognized-as-an-internal-or-external-command). – Lapo Jul 12 '19 at 17:36
  • Everything worked before resetting your PC? Are you sure some of the settings weren't adjusted when the IDE restarted? Or did you restart before testing to see if your config changes worked? – Vince Jul 12 '19 at 17:49
  • @VinceEmigh I checked and nothing has changed. It never worked. – Lapo Jul 12 '19 at 17:50

2 Answers2

2

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 tried 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!

Lapo
  • 882
  • 1
  • 12
  • 28
0

If the version of IntelliJ you have supports it, please enable it in the language level setting https://www.jetbrains.com/help/idea/project-page.html

Titu
  • 11
  • 1
  • 4
  • Ah, sorry, didn't read it carefully. It also says in one of the answers that it's a known bug and will be fixed (see https://stackoverflow.com/a/50374241/4964685) – Titu Jul 12 '19 at 17:40
  • @TituBG It says that it was solved in version 2018.2. I have 2019.1.3. Moreover a lot of people are using Java 12 features successfully. – Lapo Jul 12 '19 at 17:42
  • @TituBG I'll try. Btw I think the problem is not the version I use, since other users mention that they are using `var` and other Java 12 features. I'll let you know if your suggestion works! – Lapo Jul 12 '19 at 17:45
  • 1
    Oh. Sorry, didn't notice that part either. I just tried it on my local installation (2019.1 on Ubuntu) and it seems to work fine. I wonder if it has anything to do with the boot JDK? I remember it used to cause issues a while back. Did you install IntelliJ with bundled JVM? – Titu Jul 12 '19 at 17:50
  • 1
    I just saw your output, @Lapo . It looks like that's your Boot JDK, the bundled 1.8 by JB. It's probably the reason you're not able to use `var` . Press 'Ctrl + Shift + A' and type 'Boot' and select the 'Swith Boot JDK' option and switch to the newer JDK and try again. If it's not that then I'm out of ideas. – Titu Jul 12 '19 at 17:54
  • @TituBG I solved and I posted the answer. Thanks a lot, it's my fault! – Lapo Jul 12 '19 at 18:05