Java中goto是關鍵字嗎?什麼是Java的保留字?Java中關鍵字有哪些?

問題:Java中goto是關鍵字嗎?

回答:goto是Java的關鍵字。goto目前被作爲Java的關鍵字保留起來。goto不能作爲標識符。(下方官方文檔裏明確指出了goto和const是關鍵字,已經用紅色標出!)


問題:什麼是標識符?

回答:標識符是用來識別物件的名稱。例如,變量名,函數名,標籤名等等。


問題:什麼是Java的保留字?

回答:保留字就是被Java保留的標識符,所以用戶不能使用保留字作爲一個標識符。中文維基百科中指出保留字有時也叫關鍵字。而英文維基百科並沒有給出此定義。本人覺得還是以英文維基百科爲主!所以我們通俗理解Java中的保留字就是:目前被保留起來,還未使用,但是在以後版本里的Java中可能會被使用的Java關鍵字。如,const和goto。


來自官方的關鍵字彙總整理:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Java Language Keywords

Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. truefalse, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.

abstract continue for new switch
assert*** default goto* package synchronized
boolean do if 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
*   not used
**   added in 1.2
***   added in 1.4
****   added in 5.0

英文維基百科:http://en.wikipedia.org/wiki/List_of_Java_keywords

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章