What is Preview Feature?
For every six months new feature is adding into Java, to make new feature permanent into Java lib, community feedback is considering to understand real time use of added new feature. So to avoid disturbances of existing production code new features are releasing as a preview feature of the version. We cannot execute/test the preview feature of java directly, we must enable preview feature to use new feature(preview feature). New feature added will be trying into real world applications and then feedback will be considered from developer community to continue the feature or to update the feature in the next coming versions.Every preview feature will be described as JEP ( JDK Enhancement Proposal ). JEP-359 is for Records in Java14
How to enable/use preview features
Enabling preview feature with compiler
for example if our program is using Java14 Records feature then we need to enable preview feature while compiling with javac
javac --enable-preview --release 14 Account.javaIn the above snippet you can notice that we have used the command --enable-preview and --release by providing java version that is 14 in our example.
Enabling preview feature with java command to run program
Here we need to enable preview feature while runing java program too.java --enable-preview RunBankIn the above code RunBank is a class which start program execution and using Account class so we must enable preview feature and current system must be installed with Java14 supporting JDK.
using with maven based application
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>13</source>
<target>13</target>
<compilerArgs>
--enable-preview
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
We need to add --enable-preview as compilerArgs in pom.xml file to enable preview feature in maven based applications
Post a Comment
Post a Comment