Java 9 下划线关键字有什么用?
在早期版本的 Java 中,**下划线**(“_”)用作**标识符**或**变量名**。自 Java 9 起,**下划线**字符成为**保留关键字**,不能用作标识符或变量名。如果我们使用单个**下划线**字符作为标识符,则程序无法编译并会抛出**编译时错误**,因为现在它是一个**关键字**,不能用作 Java 9 或更高版本中的变量名。
示例
public class UnderscoreKeywordTest {
public static void main(String args[]) {
int _ = 50
System.out.println(_);
}
}输出
UnderscoreKeywordTest.java:3: error: as of release 9, '_' is a keyword, and may not be used as an identifier int _ = 50; ^ UnderscoreKeywordTest.java:4: error: as of release 9, '_' is a keyword, and may not be used as an identifier System.out.println(_);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP