简体   繁体   中英

What is the use of C option in jshell

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM