Fix Version/s: 11
Compatibility Kind:source, binary, behavioral
Compatibility Risk Description:This is a new option of jshell. We do not expect compatibility risk associated with the change given that, if the --enable-preview flag is not enabled, jshell should behave exactly as before this change.
Interface Kind:add/remove/modify command line option
Update the jshell tool to support the use of "preview" features.
JEP 12  describes JDK support for "preview" language and VM features.The jshell tool should support this as a documented flag.
JEP 12  describes how the compiler, VM and related toolchain might support preview features. A preview feature is, as per JEP description "a new feature of the Java SE Platform that is fully specified, fully implemented, and yet impermanent". In the jshell tool, support for preview features is enabled via a new command-line option, namely --enable-preview. This option effectively unlocks a new source level in which all preview features defined for a given Java SE release are enabled.
As part of this change, we plan to add a new jshell command-line flag, namely
--enable-preview flag is present, jshell will pass the
-source N (or equivalent) options to javac (via the compiler API) when compiling any snippets, where N is the current language version. And pass on the
--enable-preview option on to the JVM for snippet execution. As always, errors and warnings from the compiler and JVM are forwarded to the user. See CSRs for preview in javac and the JVM: JDK-8200312 and JDK-8200440.
--enable-preview flag is not present, jshell should continue to behave normally - e.g. as if preview features did not exist. As a result, any reference to preview features, either direct (e.g. directly in entered snippets) or indirect (e.g. through dependency on external classfiles) should result in an error. To help the user, jshell where possible (via the compiler)
will signal that a preview feature was found but no corresponding
--enable-preview flag was supplied.
This change does not alter any of the public JShell API or SPI:
jdk.jshell.tool.JavaShellToolBuilder.run(String... arguments) will successfully take the new option (the options accepted are not specified in this method/interface/package).