突然产生一个疑问:Java 中 null 是关键字吗?
于是我google了一下:

这些博客为什么都长一样暂且不讨论,就这个权重第一的答案我认为有问题。为了严谨些,在官方文档中寻求答案往往是最可靠的:1
While true and false might appear to be keywords, they are technically boolean literals (§3.10.3). Similarly, while null might appear to be a keyword, it is technically the null literal (§3.10.7).
官方文档说了,人家只是看起来像,但是并不是,true、false也不是,只是字面量。
附正经的关键字们:
abstract continue for new switch
assert default if package synchronized
boolean do goto private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while
本文探讨了Java中null是否为关键字的问题,并引用官方文档解释null实际上只是字面量而非关键字。同时澄清了true和false同样不是关键字,而是布尔字面量。
2129

被折叠的 条评论
为什么被折叠?



