JDK20 + preview features
已回答
Hello,
I'm using openjdk-20 and would like to compile code with preview features. In my project settings, SDK is JDK20 and language level is X-Experimental Features. In Javac Compiler (Preferences), I set Bytecode version = 20 and Additional Command Line parameters are --enable-preview --source 20. Still, when I build the project I get
java: invalid source release 19 with --enable-preview
(preview language features are only supported for release 20)
What am I doing wrong?
请先登录再写评论。
Ella Ananieva
@... thanks for reaching out!
* Yes
* Intellij
* IntelliJ IDEA 2022.1 (Community Edition)
Build #IC-221.5080.210, built on April 11, 2022
Runtime version: 11.0.14.1+1-b2043.25 x86_64
Ella Ananieva it's indeed not working this way on 2022.1.x, pls try latest 2022.2 or 2022.3 EAP, it's working there
@Sergei Riabinin Thank you! It helped
Another question: even though compilation succeeds, the code that includes preview features is underlined red. Is there a way to fix this?
Currently we provide support for java 19 (full support should be available in 2022.3 release), but not for java 20 yet, it will be available in future updates (probably 2023 EAP), you can keep an eye on our blog.
If you have a certain code sample to deal with, please raise a feature ticket here https://youtrack.jetbrains.com/issues/IDEA (for subsystem "Java") so we can have a closer look, thank you