15 (Preview) --Sealed types, records, patterns, local enums and interfaces
"in Language levelNew features in Java 15 require IntelliJ newer than 2020.2. Click here for 2020.2 update information If the version is old, please update it by the following method.
You can update automatically from Help> Check for Updates ... Press the ʻupdate and restart` button and wait and you're done.
Download and update the specified version of the file from here You can also. The installation wizard will ask you if you want to erase the old version and keep the settings.
Open IntelliJ and create a new project. If you select Download JDK from the pull-down, the selected distribution and version of the JDK will be set as the JDK used in your project. If you want to use the Early Access version that is not displayed here, please specify the JDK downloaded by "Add JDK ..." after downloading by yourself. (Specify the directory where bin and lib are located.)
Open File> Project Structure> Project Settings> Modules.
From the Language level pull-down, specify the one that matches the function you want to use.
Since I will try records this time, I specified " 15 (Preview) --Sealed types, records, patterns, local enums and interfaces
".
If Java 15 is not set, please check the IntelliJ version and Java version again.
First, create a Record class.
package records;
public record ExampleRecord(String name, int age) {
}
Next, create a Main class to execute.
package main;
import records.ExampleRecord;
public class Main {
public static void main(String[] args) {
ExampleRecord exampleRecord = new ExampleRecord("test", 20);
System.out.println(exampleRecord);
}
}
When I run it, it looks like this!
{JDK_path}\bin\java.exe --enable-preview "-javaagent:{IntelliJ IDEA_path}\lib\idea_rt.jar=50507:{IntelliJ IDEA_path}\bin" -Dfile.encoding=UTF-8 -classpath {workspace_path}\{project_name}\out\production\record_refrection main.Main
ExampleRecord[name=test, age=20]
The point is that --enable-preview
is given as an option.
This allows you to use the preview function Record.
That's it.
Recommended Posts