Java标识符,关键字,保留字三者区分(主要是从官网摘抄)

区分

标识符(Identifiers)

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.

关键字(keyword)

50 character sequences, formed from ASCII letters, are reserved for use as keywords and cannot be used as identifiers (现在已经变成了51个,除了const,goto,还包括了_)
The keywords const and goto are reserved, even though they are not currently used.
The keyword _ (underscore) is reserved for possible future use in parameter declarations.

易混

  • true and false are not keywords, but rather boolean literals
  • null is not a keyword, but rather the null literal
  • var and yield are not keywords, but rather restricted identifiers .
  • A further ten character sequences are restricted keywords: open, module, requires, transitive, exports, opens, to, uses, provides, and with.

保留字(reserved word)

没在官方文档上找到明确的解释
但提到不能被用做标识符的有这几类
An identifier cannot have the same spelling (Unicode character sequence) as a keyword, boolean literal , or the null literal , or a compile-time error occurs.

  1. 关键字(keyword)
  2. true, false
  3. null
    还有一个办法可以看是不是保留字,直接在编译器中试试
int var =9;//这个是可以的
var var = 9;//也是可以的
int const = 9;//不行,这也说明了,保留关键字其实也是被算作关键字的

总结

保留字如果是指不能被用户拿来做为标识符,那么关键字就是保留字的子集
保留字如果是指现阶段确定但未被使用的关键字,那么保留字就是关键字的子集

下面是官方文档链接,诸位可以自己去找
java8
java15

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值