What are the different "/types" commands in JShell in Java 9?



JShell tool has introduced in Java 9 version. It is also called a REPL(Read-Evaluate-Print-Loop) tool that allows us to execute Java code and getting immediate results. We need to list out the declared types like class, interface, enum, and etc by using the "/types" command.

Below are the different "/types" commands in JShell.

/types
/types [ID]
/types [Type_Name]
/types -start
/types -all
  • /types: This command lists all active types (class, interface, enum) created in JShell.
  • /types [ID]: This command displays the type corresponding to the id [ID].
  • /types [Type_Name]: This command displays the type corresponding to [Type_Name].
  • /types -start: This command allows us to list the types that have been added to the JShell startup script
  • /types -all: This command allows us to list all types of the current session (active, inactive and loaded when JShell starts).

In the below code snippet, created class, interface, and enum types. Then, we can apply different "/types" commands. 

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

Advertisements