How to list all the classes, interfaces, and enums in JShell in Java 9?

JavaObject Oriented ProgrammingProgramming

The JShell tool also called REPL(Read-Evaluate-Print-Loop) introduced in Java 9 that allows us to execute Java code and getting immediate results. We can quickly evaluate expressions or short algorithms without creating a new project, compile or build it. With the help of JShell, we can execute expressions, use imports, define classes, methods, and variables.

We can list out all the classes, interfaces and enums defined in the current JShell session by using "/types" command.

In the below code snippet, we have created the "Test" class, "TestInterface" interface, and enum "EnumTest" in the JShell tool.

C:\Users\User> jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> class Test {
...>       public static void main(String args[]) {
...>          System.out.println("TutorialsPoint");
...>       }
...>    }
| created class Test

jshell> interface TestInterface {
...>       public void sum();
...>    }
| created interface TestInterface

jshell> enum EnumTest {
...>       TUTORIALSPOINT,
...>       TUTORIX
...>    }
| created enum EnumTest


In the below code snippet, list out all the classes, interfaces, and enums by using "/types" command.

jshell> /types
|   class Test
|   interface TestInterface
|   enum EnumTest

jshell>
raja
Published on 31-Mar-2020 08:47:01
Advertisements