亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

關于java標識符

oracle官網的Java Language Specification文檔是這樣描述Identifiers的:
??????? An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
Identifier:
IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
JavaLetter {JavaLetterOrDigit}
JavaLetter:
any Unicode character that is a "Java letter"
JavaLetterOrDigit:
any Unicode character that is a "Java letter-or-digit"

A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.

A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true.

The "Java letters" include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ sign should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.

The "Java digits" include the ASCII digits 0-9 (\u0030-\u0039).

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.

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), or a compile-time error occurs.

Two identifiers are the same only if they are identical, that is, have the same Unicode character for each letter or digit. Identifiers that have the same external appearance may yet be different.

For example, the identifiers consisting of the single letters LATIN CAPITAL LETTER A (A, \u0041), LATIN SMALL LETTER A (a, \u0061), GREEK CAPITAL LETTER ALPHA (A, \u0391), CYRILLIC SMALL LETTER A (a, \u0430) and MATHEMATICAL BOLD ITALIC SMALL A (a, \ud835\udc82) are all different.

Unicode composite characters are different from their canonical equivalent decomposed characters. For example, a LATIN CAPITAL LETTER A ACUTE (á, \u00c1) is different from a LATIN CAPITAL LETTER A (A, \u0041) immediately followed by a NON-SPACING ACUTE (′, \u0301) in identifiers. See The Unicode Standard, Section 3.11 "Normalization Forms".

Examples of identifiers are:
??? String
??? i3
??? αρετη
??? MAX_VALUE
??? isLetterOrDigit

????大概意思就是說,標識符是由java字母和java數字組成的,而字母和數字可以從整個Unicode字符集中抽?。杭碼scii編碼中的大小寫字母 A-Z (\u0041-\u005a) and a-z (\u0061-\u007a)、數字digits 0-9 (\u0030-\u0039)、下劃線underscore (_, or \u005f)、$符dollar sign ($, or \u0024)以及除ascii字符集的Unicode字符集組成(Unicode字符集包含ascii);其中標識符的首個字符編碼不為數字,即編碼不能在(\u0030-\u0039)范圍中;

????所以說中文也可以做標識符;為了規范代碼,我們一般使用ascii字符集的字符來組成標識符,而不用中文等Unicode字符集的字符

文檔地址(java8):https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8


正在回答

1 回答

對的,但一般不建議使用中文作為標識符

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第一季(IDEA工具)升級版
  • 參與學習       1167472    人
  • 解答問題       18748    個

0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始

進入課程

關于java標識符

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號