Character values between 0 and 255 can be denoted by octal literals from "\000"
to "\377"
.
So shouldn't "\400"
be a compile-time error? Eclipse does not complain, however... what's going on here?
Character values between 0 and 255 can be denoted by octal literals from "\000"
to "\377"
.
So shouldn't "\400"
be a compile-time error? Eclipse does not complain, however... what's going on here?
「\40」+「0」と解釈しています
Java 言語仕様では、これについてここで説明しています。
OctalEscape:
\ OctalDigit
\ OctalDigit OctalDigit
\ ZeroToThree OctalDigit OctalDigit
OctalDigit: one of
0 1 2 3 4 5 6 7
ZeroToThree: one of
0 1 2 3
の構築に該当します。
\ OctalDigit OctalDigit
... '0' が続きます。該当しません
\ ZeroToThree OctalDigit OctalDigit
...だから、あいまいでも範囲外でもありません。詳細については、Java 言語仕様のセクション 3.10.6を参照してください。
まさにこの理由で、文字リテラルとして使用できないことに注意してください。
char x = '\377'; // Fine
char y = '\400'; // Error: unclosed character literal