
JShell 工具已经在Java 9 版本中引入。它也被称为REPL(Read-Evaluate-Print-Loop)工具,允许我们执行Java代码并立即获得结果。我们可以使用"/types"命令列出声明的类型,如class、interface、enum等。
以下是JShell中不同的"/types"命令。
<strong>/types /types [ID] /types [Type_Name] /types -start /types -all</strong>
- /types: 这个命令列出了在JShell中创建的所有活动类型(类,接口,枚举)。
- /types [ID]: 这个命令显示与id [ID] 对应的类型。
- /types [Type_Name]: 这个命令显示与 [Type_Name] 对应的类型。
- /types -start: 这个命令允许我们列出已添加到JShell启动脚本的类型。
- /types -all: 这个命令允许我们列出当前会话的所有类型(活动的,非活动的和在JShell启动时加载的)。
在下面的代码片段中,创建了类,接口和枚举类型。然后,我们可以应用不同的"/types"命令。
<strong>jshell> enum Operation {
...> ADDITION,
...> DIVISION;
...> }
| created enum Operation
jshell> class Employee {
...> String empName;
...> int age;
...> public void empData() {
...> System.out.println("Employee Name is: " + empName);
...> System.out.println("Employee Age is: " + age);
...> }
...> }
| created class Employee
jshell> interface TestInterface {
...> public void sum();
...> }
| created interface TestInterface
jshell> /types
| enum Operation
| class Employee
| interface TestInterface
jshell> /types 1
| enum Operation
jshell> /types -start
jshell> /drop Operation
| dropped enum Operation
jshell> /types -all
| enum Operation
| class Employee
| interface TestInterface</strong>











