Java 9 の JShell で ID によってコード スニペットを実行するにはどうすればよいですか?

WBOY
リリース: 2023-08-30 22:17:02
転載
1325 人が閲覧しました

在Java 9的JShell中,我们如何通过ID执行代码片段?

JShell is an interactive tool (REPL) introduced in Java 9. We can execute snippets like expressions, variables, methods, classes, and etc without a main () method in the JShell tool.

We can execute any prior snippet by simply typing /id, which indicates the snippet’s ID. For instance, if we type "/1", then JShell can display the first snippet that we have entered, executes it, and shows the result. We can re-execute the last snippet that we have entered (whether it is valid or invalid) by using "/!".

In the below code snippet, we have created a set of snippets, and execute those snippets by using /1, /2, /3, and /4.

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

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>
ログイン後にコピー

在下面的代码段中,我们可以使用"/!"命令重新执行上一个代码段。

<strong>jshell> 2+5
$1 ==> 7

jshell> 10-6
$2 ==> 4

jshell> /1
2+5
$3 ==> 7

jshell> /!
2+5
$4 ==> 7</strong>
ログイン後にコピー

以上がJava 9 の JShell で ID によってコード スニペットを実行するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:tutorialspoint.com
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!