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 - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 Linux新版
SublimeText3 Linux最新版