Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Java

Sửa đổi trình soạn thảo mặc định của JShell trong Java 9

JShell triển khai REPL (Read-Evaluate-Print Loop): đọc code từ dòng lệnh, đánh giá và in kết quả.

Trong JShell, có thể chỉnh sửa code bằng JShell Editor Pad. Dùng lệnh /set để thay đổi trình soạn thảo mặc định. Khi chạy /edit, trình soạn thảo mới sẽ được mở. Cú pháp: /set editor [editor].

Ví dụ đặt Notepad làm mặc định: /set editor notepad.exe.

jshell> /set editor | /set editor -default
jshell> int i = 20
i ==> 20
jshell> double j = 30.0
j ==> 30.0
jshell> /set editor notepad.exe
| Editor set to: notepad.exe
jshell> /edit

Khi chạy /edit, Notepad sẽ mở ra để chỉnh sửa code.

Sửa đổi trình soạn thảo mặc định của JShell trong Java 9

Nếu đặt chương trình không tồn tại hoặc sai đường dẫn, JShell không báo lỗi lúc set, chỉ báo khi chạy /edit:

jshell> /set editor emacs
| Editor set to: emacs
jshell> /set editor
| /set editor emacs
jshell> /edit
| Edit Error: process IO failure: Cannot run program "emacs": CreateProcess error=2, The system cannot find the file specified