简体   繁体   English

在jshell中使用C选项有什么用

[英]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指南介绍,但在jshell中找不到关于-C选项的描述/示例。

$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: 您可以使用此选项来使用javac命令行参数 ,例如考虑以下代码:

String str = (String)"Hello"

Starting jshell normally and using the same would result as: 正常启动jshell并使用相同的结果将导致:

在此输入图像描述


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 - 而在同一时间,您可以在警告(使编译器错误-Werror )和利用的-Xlint重点cast在编译时警告你在使用上面的代码使用显式铸造-

jshell -C-Xlint:cast -C-Werror

and the same statement would result into warnings and error from Jshell compiler as:- 并且相同的语句会导致Jshell编译器发出警告和错误:

在此输入图像描述


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. 虽然IMO,但就使用JShell -C命令行选项时所有标志应/不应使用的内容而言,这肯定记载得更少。

To pass options to the javac compiler that jshell is going to run to compile the statements in your REPL. 要将选项传递给jshell将运行以编译REPL中的语句的javac编译器。 One simple example (to see which classes are loaded), jshell -C-verbose . 一个简单的例子(看看加载了哪些类), jshell -C-verbose See also Standard Options for javac and Extra Options for javac for additional options you might specify. 有关您可能指定的其他选项,另请参阅javac的标准选项javac的额外选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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