IntelliJ IDE (Community Version) doesn't support var declaration Java 10
Asked Answered
A

2

9

I've installed the version 2018.1 of IntelliJ IDEA (COMMUNITY EDITION), which added support for Java 10.

When I tried to use new "var" to type local variable, the IDE highlights it with red colour and the lovely phrase: "Cannot resolve the type "var". Please see attachment varRed

I've read another post that happens exactly the same issue in which a member gave a possible solution https://mcmap.net/q/1315643/-intellij-idea-no-code-completion-for-java-10-39-var-39

I've done that as well, I've created a live template for that type for Java statement but it still doesn't work.

Some of you got any suggestion for that? I will appreciate your help

Thanks in advance.
enter image description here

Azpurua answered 10/4, 2018 at 3:50 Comment(2)
Make sure the project/module SDK and the language level used is set to JDK10. Using community version, I can confirm it works fine.Triplicate
That is correct @nullpointer. Thanks, it works!Azpurua
W
10

To expand on nullpointer's comment, there are a few things you need to verify:

  1. Make sure you've downloaded an updated SDK (version 10 or higher). I recommend using sdkman to install the SDK because it helps manage multiple versions. SDKMAN
  2. Hit cmd; to open Project Structure
  3. For Project SDK, select your updated java SDK
  4. For Project language level, select the corresponding level
  5. Now navigate to Modules, and make sure the correct language level is selected here too. I recommend selecting "Project default" to avoid future confusion.

As a troubleshooting step, it's also helpful to compile on the command line with maven or gradle to make sure it is an IDE configuration issue.

Weimer answered 5/11, 2018 at 15:58 Comment(2)
Thank you. In my case the Modules were set to 8.Abnaki
Been struggling since 1-2 weeks, the solution was point 5 of your answer. Thank you so much :)Dalrymple
Q
1

Similar problem for my project written for JDK 1.8. All we need to do is to do changes on two aforementioned places :

Project settings - 1

Project settings - 2

And the most important

Quantitative answered 21/4, 2023 at 7:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.