JShell (Java 9) là công cụ REPL (Read-Evaluate-Print-Loop) cho phép thực thi mã Java và xem kết quả ngay. Lệnh /types liệt kê các kiểu đã khai báo (class, interface, enum...).
Các biến thể lệnh /types:
/types /types [ID] /types [Type_Name] /types -start /types -all
- /types: liệt kê tất cả kiểu đang active trong session.
- /types [ID]: hiển thị kiểu tương ứng với ID.
- /types [Type_Name]: hiển thị kiểu theo tên.
- /types -start: liệt kê các kiểu trong script khởi động JShell.
- /types -all: liệt kê tất cả kiểu của session (active, inactive, loaded at startup).
Ví dụ minh họa
jshell> enum Operation { ...> ADDITION, ...> DIVISION; ...> } | created enum Operation
jshell> class Employee { ...> String empName; ...> int age; ...> public void empData() { ...> } ...> } | created class Employee
jshell> interface TestInterface { ...> public void sum(); ...> } | created interface TestInterface
jshell> /types | enum Operation | class Employee | interface TestInterface
jshell> /types 1 | enum Operation
jshell> /types -start
jshell> /drop Operation | dropped enum Operation
jshell> /types -all | enum Operation | class Employee | interface TestInterface