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中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

記事本++7.3.1
好用且免費的程式碼編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3 Linux新版
SublimeText3 Linux最新版