ホームページ  >  記事  >  Java  >  Java 9のJShellで以前に入力したフラグメントを出力するにはどうすればよいですか?

Java 9のJShellで以前に入力したフラグメントを出力するにはどうすればよいですか?

PHPz
PHPz転載
2023-09-13 12:49:02622ブラウズ

如何在Java 9的JShell中打印先前键入的片段?

JShell is an official Read-Evaluate-Print-Loop (REPL) introduced in Java 9. It provides an interactive shell for quickly prototyping, debugging, and learning Java and Java API without the need for a main() method.

The "/list" command in JShell prints out all of the previously typed snippets of that particular session with a unique identifier called the snippet ID. By default, the output doesn't contain any snippet with only valid statements or expressions that can be shown. We need to see all previously typed code include errors, then pass the -all argument to the /list command.

In the below code snippet, we have created some statements like expression, class, method, and etc in JShell.

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

jshell> int x=20
x ==> 20

jshell> "Java 9"
$2 ==> "Java 9"

jshell> System.out.println($2)
Java 9

jshell> class Test {
...> }
| created class Test

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

jshell> print()
Tutorialspoint

jshell> System.out.println(x)
20</strong>

在下面的代码片段中,我们可以使用"/list"命令查看所有先前输入的代码片段。

<strong>jshell> /list

1 : int x=20;
2 : "Java 9"
3 : System.out.println($2)
4 : class Test {
}
5 : void print() {
System.out.println("Tutorialspoint");
}
6 : print()
7 : System.out.println(x)
</strong>

以上がJava 9のJShellで以前に入力したフラグメントを出力するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はtutorialspoint.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。