How to enable records in IJ Ultimate 2020.3?

Answered

Hello,

To try Java records, I have the following method in a scratch file:

private static void scratchMethod() {
record Point(int x, int y) {};
Point myPoint = new Point(7, 50);
System.out.println(myPoint);
}

The project SDK is 15.0.2 and the project language level is "15 - Text blocks".  However, when I try to run the scratch, I get a "build failed" error:

records are a preview feature and are disabled by default.
(use --enable-preview to enable records)

I have set in Settings -> Build, Execution, Deployment -> Java Compiler -> Javac Options -> Additional Command Line Parameters, the following options: --enable-preview --release 15

But I keep getting the same compilation error.  How to fix this and get records to work?

Thank you.

 

 

 

 

0
3 comments

You need to set Language level to "15 (Preview)", and accept experimental feature alert:

 

After that you can use preview features in the project itself. However, scratch files do not take this setting into consideration, here is the bug about that: 

https://youtrack.jetbrains.com/issue/IDEA-227060

0
Avatar
Permanently deleted user

I have a Java project (no Maven, no Gradle, just IntelliJ) and I am using records... it compiles fine, but when I try to run the tests with IntelliJ, it complains:

java: records are a preview feature and are disabled by default.
  (use --enable-preview to enable records)

This is wrong, records are stable in JDK 16. To get the tests to run in IntelliJ, I need to select Language Level 16 with Preview (sealed interfaces).

IntelliJ version 2021.1.3

 

0

Hello,

Please check the latest available version: https://www.jetbrains.com/idea/nextversion/

Does it work correct for you? Thanks

0

Please sign in to leave a comment.