Java9中下划线关键字的用法
在Java的早期版本中,下划线 (_)用作标识符或创建变量名。从Java9开始,下划线字符是保留关键字,不能用作标识符或变量名。如果我们使用单个下划线字符作为标识符,则该程序将无法编译并抛出编译时错误,因为它现在是关键字,在Java9或更高版本中不能用作变量名。
示例
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(_);
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬