Java 9引入了JShell,它允许我们评估代码片段,例如声明、语句和表达式。 在下面的代码片段中,我们创建了变量x、y和str。我们可以使用"/list"命令查看所有输入的代码片段。之后,我们可以使用"/reset"命令来重置当前会话。 jshell> int a = 25 a ==> 25 jshell> double y = 30 y ==> 30.0 jshell> String str
类外部的声明或接口(以及类和接口本身的声明)是根据以下规则创建的。 外部声明规则: 1) 可以忽略public、protected和private等访问修饰符。所有其他片段都可以访问所有声明片段。 jshell> private int i = 10; i ==> 10 jshell> System.out.println(i); 10登录后复制 jshell> final class A {vo
A switch statement can test multiple conditions just like an else clause and handles the default possibility. The default clause can be executed when none of the cases match, and a break statement can
在下面的示例中,我们可以在JShell中实现一个lambda表达式。 C:UsersUser>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> Consumer s = (String s) -> System.out.println(s) s ==> $Lambd
If we want to get the current date with time in JShell by using the below code snippet. C:UsersUser>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> new Date