Java 9 中 JShell 的不同“/types”命令是什么?
JShell 工具是在 Java 9 版本中引入的。它也称为 REPL(读取-评估-打印-循环)工具,允许我们执行 Java 代码并获得即时结果。我们需要使用“/types”命令列出声明的类型,例如 class、interface、enum 等。
以下是 JShell 中不同的“/types”命令。
/types /types [ID] /types [Type_Name] /types -start /types -all
- /types: 此命令列出在 JShell 中创建的所有活动类型(类、接口、枚举)。
- /types [ID]: 此命令显示与 id [ID] 对应的类型。
- /types [Type_Name]: 此命令显示与 [Type_Name] 对应的类型。
- /types -start: 此命令允许我们列出已添加到 JShell 启动脚本中的类型
- /types -all: 此命令允许我们列出当前会话的所有类型(活动、非活动以及 JShell 启动时加载的类型)。
在下面的代码片段中,创建了类、接口和枚举类型。然后,我们可以应用不同的“/types”命令。
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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP