A preview feature is a new feature whose design, specification, and implementation are complete, but which is not permanent, which means that the feature may exist in a different form or not at all in future JDK releases.
Introducing a feature as a preview feature in a mainline JDK release enables the largest developer audience possible to try the feature out in the real world and provide feedback. In addition, tool vendors are encouraged to build support for the feature before Java developers use it in production. Developer feedback helps determine whether the feature has any design mistakes, which includes hard technical errors (such as a flaw in the type system), soft usability problems (such as a surprising interaction with an older feature), or poor architectural choices (such as one that forecloses on directions for future features). Through this feedback, the feature's strengths and weaknesses are evaluated to determine if the feature has a long-term role in the Java SE Platform, and if so, whether it needs refinement. Consequently, the feature may be granted final and permanent status (with or without refinements), or undergo a further preview period (with or without refinements), or else be removed.
Every preview feature is described by a JDK Enhancement Proposal (JEP) that
defines its scope and sketches its design. For example, JEP 325 describes the JDK 12 preview feature for
expressions. For background information about the role and lifecycle of preview
features, see JEP 12.
Using Preview Features
To use preview language features in your programs, you must explicitly enable them in the compiler and the runtime system. If not, you'll receive an error message that states that your code is using a preview feature and preview features are disabled by default.
To compile source code with
javac that uses preview features from
JDK release n, use
javac from JDK
release n with the
command-line option in conjunction with either the
--release n or
-source n command-line option.
For example, suppose you have an application named
uses the JDK 12 preview language feature
Compile this with JDK 12 as follows:
javac --enable-preview --release 12 MyApp.java
When you compile an application that uses preview features, you'll receive a warning message similar to the following:
Note: MyApp.java uses preview language features. Note: Recompile with -Xlint:preview for details
Remember that preview features are subject to change and are intended to provoke feedback.
To run an application that uses preview features from JDK release n, use
java from JDK release n with the
--enable-preview option. To
continue the previous example, to run
java from JDK 12 as follows:
java --enable-preview MyApp
Note:Code that uses preview features from an older release of the Java SE Platform will not necessarily compile or run on a newer release.
javadoc also support the
--enable-preview command-line option.
You can provide feedback on preview features, or anything else about the Java SE Platform, as follows:
- If you find any bugs, then submit them at Java Bug Database.
- If you want to provide substantive feedback on the usability of a preview feature, then post it on the OpenJDK mailing list where the feature is being discussed. To find the mailing list of a particular feature, see the feature's JEP page and look for the label Discussion. For example, on the page JEP 325: Switch Expressions (Preview), you'll find "Discussion amber dash dev at openjdk dot java dot net" near the top of the page.
- If you are working on an open source project, then see Quality Outreach on the OpenJDK Wiki.