Home > Java > javaTutorial > body text

How to re-execute existing JShell fragment in Java 9?

PHPz
Release: 2023-08-18 20:37:02
forward
1010 people have browsed it

在Java 9中如何重新执行现有的JShell片段?

JShell 是在Java 9中引入的第一个REPL工具。我们可以使用JShell工具在命令行提示符中执行简单的代码片段。我们可以通过输入"jshell"命令来启动JShell会话,通过输入"/exit"命令来停止会话,并通过使用"/help"命令搜索特定命令。

可以使用"/reload"命令重新执行JShell中的所有现有代码片段。我们还可以使用"/reset"命令从JShell会话中删除所有先前的代码。

在下面的代码片段中,我们创建了一组代码片段。

<strong>jshell> 2+10
$1 ==> 12

jshell> String s = "Tutorialspoint"
s ==> "Tutorialspoint"

jshell> System.out.println("Tutorialspoint")
Tutorialspoint

jshell> int num1 = 25
num1 ==> 25

jshell> /1
2+10
$5 ==> 12

jshell> /2
String s = "Tutorialspoint";
s ==> "Tutorialspoint"

jshell> /3
System.out.println("Tutorialspoint")
Tutorialspoint

jshell> /4
int num1 = 25;
num1 ==> 25</strong>
Copy after login

I在下面的代码片段中,我们可以应用"/reload"命令。Jshell工具重新执行所有现有的代码片段并打印出来。

<strong>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;</strong>
Copy after login

在下面的代码片段中,我们可以使用"/reset"命令来删除JShell会话中的所有先前代码,并打印"Resetting State"。

<strong>jshell> /reset
| Resetting state.

jshell></strong>
Copy after login

The above is the detailed content of How to re-execute existing JShell fragment in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template