首页  >  文章  >  Java  >  在Java 9中,下划线关键字的用途是什么?

在Java 9中,下划线关键字的用途是什么?

PHPz
PHPz转载
2023-09-09 14:49:021410浏览

在Java 9中,下划线关键字的用途是什么?

在早期版本的 Java 中,下划线(“_”)已用作标识符或创建 变量名称。从 Java 9 开始,下划线字符是一个保留关键字,不能用作标识符或变量名。如果我们使用单个下划线字符作为标识符,程序将无法编译并抛出编译时错误,因为现在它是一个 关键字,并且在 Java 9 或更高版本中不能用作变量名称。

示例

public class UnderscoreKeywordTest {
   public static void main(String args[]) {
      int _ = 50
      System.out.println(_);
   }
}

输出

<strong>UnderscoreKeywordTest.java:3: error: as of release 9, &#39;_&#39; is a keyword, and may not be used as an identifier
int _ = 50;
^
UnderscoreKeywordTest.java:4: error: as of release 9, &#39;_&#39; is a keyword, and may not be used as an identifier
System.out.println(_);</strong>

以上是在Java 9中,下划线关键字的用途是什么?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除