爪哇 9下划线(_)关键字
In this post, we will see about Underscore
keyword, which is 整型roduced in 爪哇 9.
爪哇下划线
Underscore(_)
is a symbol that is used to combine multi-words in a single identifier
sometimes refers to a 变量 在编程环境中。
In 爪哇, to create a lengthy 变量, we prefer to use underscore (_)
such as employee_id
, employee_name
etc.
Apart from it, underscore
can be used to represent a 变量 and can hold any type of value . Since 爪哇 8,我们可以使用下划线作为变量名称,例如 = 10, = 10.5, etc. But in 爪哇 9, underscore is a reserve word
and cannot
be用作标识符.
让’s see an example.
下划线作为竞彩篮球分析 8中的变量
通过使用竞彩篮球分析 8执行此示例,并产生带有警告消息的输出。查看输出。
1 2 3 4 5 6 7 8 |
上市 类 主要{ 上市 静态的 虚空 主要(串[] args) { 整型 _ = 10; //有效期至竞彩篮球分析 8 系统.出.打印(_); } } |
输出量
警告:‘_’用作标识符
(用于‘_’因为在竞彩篮球分析 SE 8之后的发行版中可能不支持标识符)
下划线作为竞彩篮球分析 9中的变量
如果我们使用竞彩篮球分析 9执行此示例,则它将报告错误。参见示例。
1 2 3 4 5 6 7 8 |
上市 类 主要{ 上市 静态的 虚空 主要(串[] args) { 整型 _ = 10; //有效期至竞彩篮球分析 8 系统.出.打印(_); } } |
输出量
Although, we can not use underscore
alone as a 变量 name, but we can use it with other alphabets. See some possible examples.
这是一个例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
上市 类 主要{ 上市 静态的 虚空 主要(串[] args) { 整型 _一个 = 10; //有效 系统.出.打印(_一个); 整型 一个_ = 20; //有效 系统.出.打印(一个_ ); 整型 一个_ b = 20; //有效 系统.出.打印(一个_ b); 整型 _ = 10; //无效 系统.出.打印(_); } } |
10
20
20
错误:‘_’不应用作标识符,因为它是源级别1.8上的保留关键字
那’s all about 爪哇 9underscore keyword.