I have gone through the introduction to jshell guide and couldn't find description/examples about the -C option in jshell.
$jshell --help
-C<flag> Pass <flag> to the compiler.
Use one -C for each compiler flag or flag argument
You can use this option to make use of javac
command line arguments for example consider this piece of code:
String str = (String)"Hello"
Starting jshell
normally and using the same would result as:
While at the same time you can enable compiler errors on warning(-Werror
) and make use of the -Xlint
key cast
while compiling to warn you of the explicit cast used in the above code using -
jshell -C-Xlint:cast -C-Werror
and the same statement would result into warnings and error from Jshell compiler as:-
Though IMO, this certainly is documented far less in terms of what all flags shall/shall not be used while using the JShell -C
command line option.
To pass options to the javac
compiler that jshell
is going to run to compile the statements in your REPL. One simple example (to see which classes are loaded), jshell -C-verbose
. See also Standard Options for javac and Extra Options for javac for additional options you might specify.
来源:https://stackoverflow.com/questions/46741317/what-is-the-use-of-c-option-in-jshell