/id is used to execute the snippet by ids.
Step 1: Open terminal and execute the command jshell.
$jshell
| Welcome to JShell -- Version 10.0.2
| For an introduction type: /help intro
jshell>
Step 2: Execute below statements.
System.out.println("Hello")
System.out.println("World")
System.out.println("!!!!!")
jshell> System.out.println("Hello")
Hello
jshell> System.out.println("World")
World
jshell> System.out.println("!!!!!")
!!!!!
Step 3: Execute the command /list to see the snippet ids.
jshell> /list
1 : System.out.println("Hello")
2 : System.out.println("World")
3 : System.out.println("!!!!!")
Step 4: Execute the command /2 to execute the statement with snippet id 2.
jshell> /2
System.out.println("World")
World
You can even execute multiple snippets in one statement. For example, /1 3 execute snippets with ids 1 and 3.
jshell> /1 3
System.out.println("Hello")
Hello
System.out.println("!!!!!")
!!!!!
You can even use - to specify start and end snippet ids. For example, /1-3 execute the snippets with ids 1, 2 and 3.
jshell> /1-3
System.out.println("Hello")
Hello
System.out.println("World")
World
System.out.println("!!!!!")
!!!!!
No comments:
Post a Comment