Is null a Java keyword?

て烟熏妆下的殇ゞ 提交于 2019-11-27 22:20:39

问题


Is null is a keyword in Java?


回答1:


No.It is not a keyword.




回答2:


Not according to the Java Language Specification list of keywords. On the other hand, this doesn't compile:

int null = 10;

The rules for identifiers specify that:

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter. An identifier cannot have the same spelling (Unicode character sequence) as a keyword (§3.9), boolean literal (§3.10.3), or the null literal (§3.10.7).

I'm not sure what the benefit of making it not-a-keyword is, to be honest.




回答3:


Not a keyword - the null literal.

an identifier (oops, no it isn't)




回答4:


null is a literal similar to true and false in Java. These are not keywords because these are the values of something. As null is the value of a reference variable, true is the value of a boolean variable.




回答5:


null is a literal, in the same sense that false, 10, and '\n' are literals. It's not a "keyword", technically, but it is a character string that is treated specially by the compiler if the compiler encounters it in a java source file.

So, no, you cannot name a variable "null". The lexical analyzer will decide that it is not an identifier.




回答6:


No. See this for complete list: Java Language Keywords




回答7:


true and false are also literals. Java trivia: const and goto are keywords.




回答8:


It represents a special value but it's not a keyword in Java, and it doesn't mean that we can use it as an identifier. It's restricted to be used as an identifier and that is obvious because we cannot have a special value as an identifier because the compiler will treat that word (null) as special value, not as identifier.




回答9:


No. null is not a keyword in Java.



来源:https://stackoverflow.com/questions/519631/is-null-a-java-keyword

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!