您好,欢迎访问一九零五行业门户网

在Java 9的JShell中,不能在顶层声明中使用哪些修饰符?

jshell 是一个用于学习java语言和原型化java代码的交互式工具。它是一个repl (read-evaluate-print-loop),一旦输入,它会立即评估声明、语句和表达式,并在jshell中立即打印结果。这个工具从命令行提示符运行。
像public、protected、private、static和final 这样的修饰符不允许在顶层声明中使用,并且可以被忽略并显示一个警告。像synchronized、native、abstract和default top-level方法这样的关键字不允许使用,并且可能会引发错误。
在下面的代码片段中,我们创建了final 和static 变量。它向用户打印一个警告消息,内容为“modifier 'final' or 'static' not permitted in top-level declarations, ignored”。
example-1c:\users\user\>jshell| welcome to jshell -- version 9.0.4| for an introduction type: /help introjshell> final int x = 0| warning:| modifier 'final' not permitted in top-level declarations, ignored| final int x = 0;| ^---^x ==> 0jshell> x = 1x ==> 1
example-2 的中文翻译为:
示例-2jshell> static string str = "tutorix"| warning:| modifier 'static' not permitted in top-level declarations, ignored| static string str = "tutorix";| ^----^str ==> "tutorix"
以上就是在java 9的jshell中,不能在顶层声明中使用哪些修饰符?的详细内容。
其它类似信息

推荐信息