January 28, 2020 /   java   java 13   enable preview features

Java 13 was released with some cool features as preview. Preview features are not enabled by default. Here are the ways to enable preview features as per use case.

Command Line

compilation

javac --enable-preview --release 13 ClassName.java

execution

java --enable-preview ClassName

IntelliJ IDEA

Go to File -> Project Structure -> Project Language Level

Maven

Provide --enable-preview in command line arguments for each java plugin.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <release>13</release>
        <compilerArgs>
            --enable-preview
        </compilerArgs>
    </configuration>
</plugin>