Java 9中的JShell中有哪些不同的“ / types”命令?
JShell 工具已在Java9 版本中引入。它也被称为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