像public、protected、private、static和final 这样的修饰符不允许在顶层声明中使用,并且可以被忽略并显示一个警告。像synchronized、native、abstract和default top-level方法这样的关键字不允许使用,并且可能会引发错误。
在下面的代码片段中,我们创建了final 和static 变量。它向用户打印一个警告消息,内容为“Modifier 'final' or 'static' not permitted in top-level declarations, ignored”。
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
jshell> static String str = "Tutorix" | Warning: | Modifier 'static' not permitted in top-level declarations, ignored | static String str = "Tutorix"; | ^----^ str ==> "Tutorix"
以上就是在Java 9的JShell中,不能在顶层声明中使用哪些修饰符?的详细内容,更多请关注php中文网其它相关文章!
已抢186920个
抢已抢67420个
抢已抢353535个
抢已抢668030个
抢已抢123365个
抢已抢25105个
抢