如何在 Java 9 中的 JShell 中设置详细模式?

javaobject oriented programmingprogramming更新于 2025/9/27 13:32:17

JShell  是 Java 9 中引入的 REPL  工具。我们可以使用此工具在 命令行 提示符中执行简单的代码片段。

当我们在 JShell 中输入 算术表达式、变量 等时,它会显示结果,但不显示所创建变量类型的详细信息。在 JShell 中,可以使用 详细模式 显示有关输入命令执行的更多信息。我们需要使用命令"/set feedback verbose"获取有关执行的命令的更多信息(命令前面可以加上"/")。

在下面的代码片段中,详细模式处于开启状态,它可以显示有关变量类型的更多信息。

C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> /set feedback verbose
| Feedback mode: verbose

jshell> 5.0 * 8
$1 ==> 40.0
| created scratch variable $1 : double

jshell> String str = "TutorialsPoint";
str ==> "TutorialsPoint"
| created variable str : String

jshell> void test() {
...> System.out.println("Tutorix");
...> }
| created method test()

jshell> test()
Tutorix

jshell> String str1 = new String("Tutorix");
str1 ==> "Tutorix"
| created variable str1 : String

jshell> "TutorialsPoint" + "Tutorix" + 2019
$6 ==> "TutorialsPointTutorix2019"
| created scratch variable $6 : String

jshell> int test1() {
...> return 10;
...> }
| created method test1()

jshell> test1()
$8 ==> 10
| created scratch variable $8 : int

相关文章


有用资源