Java 9中JShell的顶级声明中不允许哪些修饰符?
JShell 是用于学习Java语言和对Java代码进行原型设计的交互式工具。它是一个REPL (读取-评估-打印循环),用于对输入的声明,语句和表达式 进行求值,并立即在JShell中打印结果。该工具从命令行提示符运行。
顶级 声明中不允许使用诸如public,protected,private,static和final之 类的修饰符,并可以通过警告将其忽略。不允许使用关键字sync,native,abstract和default顶级方法,它们可能是error。
在下面的代码段中,我们创建了final 和static 变量。它向用户输出一条警告消息,指出“顶层声明中不允许使用修饰符'final'或'static',而忽略了”。
示例1
C:\Users\User\>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> final int x = 0 | Warning: | Modifier 'final' not permitted in top-level declarations, ignored | final int x = 0; | ^---^ x ==> 0 jshell> x = 1 x ==> 1
示例2
jshell> static String str = "Tutorix" | Warning: | Modifier 'static' not permitted in top-level declarations, ignored | static String str = "Tutorix"; | ^----^ str ==> "Tutorix"
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短