เครื่องมือ JShell ถูกนำมาใช้ใน Java 9 ยังเรียกว่าเครื่องมือ REPL (Read-Evaluate-Print-Loop) ที่ช่วยให้เราสามารถรันโค้ด Java และได้ผลลัพธ์ทันที เราต้องแสดงรายการประเภทที่ประกาศไว้ เช่น class, interface, enum ฯลฯ โดยใช้คำสั่ง "/types"
ด้านล่างคือคำสั่ง "/types" ต่างๆ ใน JShell:
/types
/types [ID]
/types [Type_Name]
/types -start
/types -all
- /types: คำสั่งนี้แสดงรายการประเภทที่ใช้งานอยู่ทั้งหมด (class, interface, enum) ที่สร้างใน JShell
- /types [ID]: คำสั่งนี้แสดงประเภทที่สอดคล้องกับ id [ID]
- /types [Type_Name]: คำสั่งนี้แสดงประเภทที่สอดคล้องกับ [Type_Name]
- /types -start: คำสั่งนี้ช่วยแสดงรายการประเภทที่ถูกเพิ่มเข้าไปในสคริป्टเริ่มต้นของ JShell
- /types -all: คำสั่งนี้ช่วยแสดงรายการประเภททั้งหมดของเซสชันปัจจุบัน (active, inactive และที่โหลดตอน JShell เริ่ม)
ในตัวอย่างโค้ดด้านล่าง สร้าง class, interface, และ enum types แล้วใช้คำสั่ง "/types" ต่างๆ:
jshell> enum Operation { ...> ADDITION, ...> DIVISION; ...> } | created enum Operation
jshell> class Employee { ...> String empName; ...> int age; ...> public void empData() { ...> System.out.println("Employee Name is: " + empName); ...> System.out.println("Employee Age is: " + age); ...> } ...> } | 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