JShell ขึ้นอยู่กับ REPL (อ่าน-ประเมิน-พิมพ์-วนซ้ำ ) ที่นำมาใช้ใน Java 9 เครื่องมือนี้สามารถใช้เพื่อดำเนินการคำสั่งอย่างง่าย ประเมินผล และพิมพ์ผลลัพธ์
A สวิตช์ แถลงการณ์ สามารถทดสอบได้หลายเงื่อนไขเหมือนกับ อื่นๆ ข้อ และจัดการกับความเป็นไปได้เริ่มต้น ค่าเริ่มต้น ข้อ สามารถดำเนินการได้เมื่อไม่มีกรณีใดตรงกัน และ แตก แถลงการณ์ สามารถใช้เพื่อแยกสวิตช์หลังจากจับคู่สำเร็จ
ในข้อมูลโค้ดด้านล่าง เราสามารถกำหนด คำสั่งสวิตช์ ใน JShell
Snippet-1
jshell> int i = 10;
i ==> 10
jshell> switch(i) {
...> case 1 : System.out.println("1");
...> case 10 : System.out.println("10");
...> default : System.out.println("default");
...> }
10
default
jshell> int i = 1;
i ==> 1
jshell> switch(i) {
...> case 1 : System.out.println("1");
...> case 10 : System.out.println("10");
...> default : System.out.println("default");
...> }
1
10
default
ในข้อมูลโค้ดด้านล่าง เราสามารถกำหนด คำสั่งเปลี่ยนด้วยการหยุดพัก ใน JShell
Snippet-2
jshell> switch(i) {
...> case 1 : System.out.println("1"); break;
...> case 10 : System.out.println("10"); break;
...> default : System.out.println("default"); break;
...> }
1