Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Java

วิธี Save, Edit และ Drop Snippet ใน JShell ของ Java 9

JShell Snippet Management

JShell เป็น REPL อย่างเป็นทางการของ Java 9 ให้ prototyping และ debugging ได้รวดเร็วโดยไม่ต้องมี main() หรือ compile ก่อน

1. Save Snippet (บันทึก)

ใช้คำสั่ง /save [-all|-history|-start] <file>

C:\Users\User>jshell
jshell> /save C:\Users\User\jshell.txt

สร้างไฟล์ jshell.txt ที่ path ที่ระบุ

2. Edit Snippet (แก้ไข)

ใช้คำสั่ง /edit จะเปิด JShell Edit Pad (external editor)

jshell> /edit
| created method empName(String,String)

วิธี Save, Edit และ Drop Snippet ใน JShell ของ Java 9

3. Drop Snippet (ลบ)

ใช้คำสั่ง /drop <id> โดย id ได้จาก /list

jshell> /drop 1
| dropped method empName(String,String)
jshell>

คำสั่งที่เกี่ยวข้อง

  • /list - แสดง snippets ทั้งหมดพร้อม id
  • /save -all - บันทึกทั้งหมด (รวม start-up snippets)
  • /save -history - บันทึกเฉพาะ history
  • /save -start - บันทึกเฉพาะ start-up snippets

สรุป

JShell ให้เครื่องมือจัดการ snippet ครบครัน: save, edit, drop ช่วยให้ workflow การ prototype สะดวกขึ้น