JShell 是Java 9中引入的REPL 工具。我们可以使用此工具在命令行提示符下执行简单的代码片段。
当我们在JShell中输入算术表达式,变量等时,它将显示结果,而不会详细说明所创建变量的类型。在JShell中,可以使用详细模式显示有关输入命令执行的更多信息。我们需要获得有关使用以下命令执行的命令的更多信息:“ / set feedback verbose ”(命令前面可以带有“ / ”)。
在下面的代码段中,详细模式为on,它可以显示有关变量类型的更多信息。
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 = "nhooo";
str ==> "nhooo"
| 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> "nhooo" + "Tutorix" + 2019
$6 ==> "nhoooTutorix2019"
| created scratch variable $6 : String
jshell> int test1() {
...> return 10;
...> }
| created method test1()
jshell> test1()
$8 ==> 10
| created scratch variable $8 : int