Auto-completion ด้วย Tab Key
JShell รองรับ auto-completion เมื่อพิมพ์ชื่อ class, variable, method ไม่ครบ กด Tab เพื่อให้ JShell ช่วยเติมหรือแสดงตัวเลือก
พฤติกรรมของ Tab Key
- Match เดียว: JShell เติมชื่อให้ครบอัตโนมัติ
- หลาย Match: แสดงรายการตัวเลือก พิมพ์ตัวอักษรเพิ่ม แล้วกด Tab อีกครั้ง
- ไม่มี Match: เล่นเสียงเตือน (alert sound)
ตัวอย่างการใช้งาน
C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
jshell> String studentName(String firstName, String lastName) {
...> return firstName + lastName;
...> }
| created method studentName(String, String)
jshell> /methods
| String studentName(String, String)
jshell> str <Press Tab Key>
studentName(
jshell> studentName(
studentName( Signatures:
String studentName(String firstName, String lastName)
<press tab again to see documentation>
jshell> studentName(
String studentName(String firstName, String lastName)
<no documentation found>
<press tab again to see all possible completions; total possible completions: 545>
ประโยชน์
- ลดการพิมพ์ผิด (typos)
- ค้นหา method signatures และ documentation ได้รวดเร็ว
- เร่งความเร็วในการ prototype และ explore API
สรุป
Tab key เป็นฟีเจอร์สำคัญของ JShell ช่วยให้เขียนโค้ดได้เร็วและถูกต้องมากขึ้น