可以使用/reload命令重新执行jshell中的所有现有代码片段。我们还可以使用/reset命令从jshell会话中删除所有先前的代码。
在下面的代码片段中,我们创建了一组代码片段。
jshell> 2+10$1 ==> 12jshell> string s = "tutorialspoint"s ==> "tutorialspoint"jshell> system.out.println("tutorialspoint")tutorialspointjshell> int num1 = 25num1 ==> 25jshell> /12+10$5 ==> 12jshell> /2string s = "tutorialspoint";s ==> "tutorialspoint"jshell> /3system.out.println("tutorialspoint")tutorialspointjshell> /4int num1 = 25;num1 ==> 25
i在下面的代码片段中,我们可以应用"/reload"命令。jshell工具重新执行所有现有的代码片段并打印出来。
jshell> /reload| restarting and restoring state.-: 2+10-: string s = "tutorialspoint";-: system.out.println("tutorialspoint")tutorialspoint-: int num1 = 25;-: 2+10-: string s = "tutorialspoint";-: system.out.println("tutorialspoint")tutorialspoint-: int num1 = 25;-: int num1 = 25;
在下面的代码片段中,我们可以使用"/reset"命令来删除jshell会话中的所有先前代码,并打印"resetting state"。
jshell> /reset| resetting state.jshell>
以上就是在java 9中如何重新执行现有的jshell片段?的详细内容。
