Java 9中引入的JShell工具也称为REPL(读取-评估-打印循环),它使我们能够执行Java代码并立即获得结果。我们可以快速评估表达式或简短算法,而无需创建,编译或构建新项目。借助JShell,我们可以执行表达式,使用导入,定义类,方法和变量。
我们可以使用“ / types ”命令列出当前JShell会话中定义的所有类,接口 和枚举 。
在下面的代码片段中,我们在JShell工具中创建了“ Test ”类,“ TestInterface ”接口和枚举“ EnumTest ”。
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("nhooo");
...> }
...> }
| created class Test
jshell> interface TestInterface {
...> public void sum();
...> }
| created interface TestInterface
jshell> enum EnumTest {
...> nhooo,
...> TUTORIX
...> }
| created enum EnumTest在下面的代码片段中,使用“ / types ”命令列出所有类,接口和枚举。
jshell> /types | class Test | interface TestInterface | enum EnumTestjshell>