JShell là công cụ dòng lệnh tương tác (REPL) trong Java 9: nhận input, đánh giá, in output.
Lệnh /vars liệt kê biến đã tạo. Các biến thể:
- /vars - Hiển thị tất cả biến active trong session hiện tại.
- /vars [ID] - Hiển thị biến và giá trị theo ID (tên do JShell gán: $1, $2...).
- /vars [Variable_Name] - Hiển thị biến theo tên do người dùng đặt.
- /vars -start - Hiển thị biến trong startup script của JShell.
- /vars -all - Hiển thị tất cả biến: active, inactive, loaded at startup.
Ví dụ thực hành
C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
jshell> 2 + 4
$1 ==> 6
jshell> /vars
| int $1 = 6
jshell> int x = 20
x ==> 20
jshell> /vars
| int $1 = 6
| int x = 20
jshell> /vars $1
| int $1 = 6
jshell> /vars x
| int x = 20
jshell> /vars -all
| int $1 = 6
| int x = 20
jshell> /drop x
| dropped variable x
jshell> /vars -all
| int $1 = 6
| int x = (not-active)