JDK20 and language level, red lines in editor?
I installed the latest JDK from Oracle (20.0.1), and created a New Project in IntelliJ (2022.3.3). I'm just using IntelliJ for the build, no gradle or maven yet. I tried to use some of the latest features and I get red underlines and errors in IntelliJ, with switch patterns for example. My "Language Level" is "SDK Default (X - Experimental features)". I see that when I open "Module Settings (F4)" > Project.
If I change the Language Level to "19 Preview", the red lines in editor go away, but I still get a compilation error.
java: invalid source release 19 with --enable-preview
(preview language features are only supported for release 20)
Even though I'm running JDK 20, there is no 20 in the list of choices for a project "Language Level".
If I change the language level back to "X- Experimental Features" and then add "--enable-preview" as both a compiler option (in Settings) and a runtime VM option (under my Run Configuration) then it works, except there are still red lines in IntelliJ's editor.
Is there any way to get the red lines to go away?
请先登录再写评论。
Hi,
Support for Java 20 is available in (since) IntelliJ IDEA 2023.1, and you are using 2022.3.3 so it's not supported . Please read this blog post for more info: https://blog.jetbrains.com/idea/2023/03/java-20-and-intellij-idea/
If you have any more questions or comments, please feel free to reach out; we would be more than happy to assist.