JShell เครื่องมือได้แนะนำใน Java 9 รุ่น เรียกอีกอย่างว่า REPL (Read-Evaluate-Print-Loop) เครื่องมือที่ช่วยให้เราสามารถรันโค้ด Java และได้ผลลัพธ์ทันที เราต้องแสดงรายการประเภทที่ประกาศเช่น คลาส , อินเทอร์เฟซ , enum และอื่นๆ โดยใช้ "/types " คำสั่ง
ด้านล่างนี้คือ "/types ที่แตกต่างกัน " คำสั่งใน JShell
/types /types [ID] /types [Type_Name] /types -start /types -all
- /ประเภท: คำสั่งนี้แสดงรายการประเภทแอ็คทีฟทั้งหมด (คลาส, อินเตอร์เฟส, enum) ที่สร้างใน JShell
- /types [ID]: คำสั่งนี้แสดงประเภทที่สอดคล้องกับรหัส [ID] .
- /types [Type_Name]: คำสั่งนี้แสดงประเภทที่สอดคล้องกับ [Type_Name] .
- /types -start: คำสั่งนี้ช่วยให้เราแสดงรายการประเภทที่เพิ่มลงในสคริปต์เริ่มต้น JShell
- /types -all: คำสั่งนี้ช่วยให้เราแสดงรายการเซสชันปัจจุบันทุกประเภท (ใช้งานอยู่ ไม่ใช้งาน และโหลดเมื่อ JShell เริ่มทำงาน)
ในข้อมูลโค้ดด้านล่าง สร้างคลาส อินเทอร์เฟซ และประเภท enum จากนั้น เราก็สามารถใช้ "/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