Maison > Java > tutoriel Java > le corps du texte

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

王林
Libérer: 2023-08-20 16:25:02
avant
913 人浏览过

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

JShell 是一个用于学习Java语言和原型化Java代码的交互式工具。它是一个REPL (Read-Evaluate-Print-Loop),一旦输入,它会立即评估声明语句表达式,并在JShell中立即打印结果。这个工具从命令行提示符运行。

publicprotectedprivatestaticfinal 这样的修饰符不允许在顶层声明中使用,并且可以被忽略并显示一个警告。像synchronizednativeabstractdefault top-level方法这样的关键字不允许使用,并且可能会引发错误

在下面的代码片段中,我们创建了final static 变量。它向用户打印一个警告消息,内容为“Modifier 'final' or 'static' not permitted in top-level declarations, ignored”。

Example-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
Copier après la connexion

Example-2

的中文翻译为:

示例-2

jshell> static String str = "Tutorix"
| Warning:
| Modifier 'static' not permitted in top-level declarations, ignored
| static String str = "Tutorix";
| ^----^
str ==> "Tutorix"
Copier après la connexion

以上是在Java 9的JShell中,不能在顶层声明中使用哪些修饰符?的详细内容。更多信息请关注PHP中文网其他相关文章!

source:tutorialspoint.com
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Derniers articles par auteur
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!