宣告識別字(identifier)有下列四個條件:
- 開頭第一個字元可為英文字母, "_"或"$", Ex: apple, $apple, _apple
- 第二個字元起可以是數字, 英文字母, "_"或"$", 且沒有字元長度限制, Ex: a1, $1, _1
- 變數名稱英文字母大小有別
- 不可為保留字(Reserved Word), 如下:
abstract | interface | boolean | break |
const | continue | default | do |
float | for | goto | if |
native | new | package | private |
strictfp | super | switch | synchronized |
void | volatile | while | assert |
byte | this | import | extends |
double | enum | public | instanceof |
implements | case | throw | return |
protected | else | catch | throws |
char | final | int | short |
transient | class | finally | long |
static | try |
//Identifier命名
class $a {} class _a {} class a1 {} public class Test { int a1; int $a; int _a; public void a1() {} public void $a() {} public void _a() {} }
沒有留言:
張貼留言