如何在 Java 9 中將原始碼載入到 JShell 中?
JShell 是一款用於學習 Java 的互動工具,它是能夠評估宣告、語句和表示式的REPL(Read-Evaluate-Print-Loop)。
離開 JShell 會話時,我們想要將之前輸入的新會話程式碼重用。這可以透過使用命令/open [File_Path]來完成。此命令將載入選項中提供的file[File_Path]中找到的所有程式碼和內部命令。
在下面的程式碼片段中,我們可以使用 "/open [File_Path]"命令,從副檔名為".jsh"的目錄中載入原始碼。
C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro
jshell> x
| Error:
| cannot find symbol
| symbol: variable x
| x
| ^
jshell> y
| Error:
| cannot find symbol
| symbol: variable y
| y
| ^
jshell> /list
jshell> /open C:\Users\User\Desktop\save.jsh
jshell> /list
1 : int x = 15;
2 : double y = 25.0;
3 : public int sum(int a, int b) {
return a + b;
}
jshell> x
x ==> 15
jshell> y
y ==> 25.0
jshell> int result = sum(5, 7)
result ==> 12
Advertisement
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP