2011-07-25 41 views

回答

8

它是將其解釋爲 「\ 40」 + 「0」

Java語言規範描述了這個here

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 
+3

就個人而言,我認爲它會更好,如果它失敗了。這是一個非常神祕的區別。 – Jay

5

它落在

\ OctalDigit OctalDigit 

建設...其次是 '0' 下。它

\ ZeroToThree OctalDigit OctalDigit 

秋天......所以它不是含糊不清或超出範圍。有關更多詳細信息,請參閱Java語言規範的section 3.10.6。你不能把它作爲一個字符字面正是這個原因

注:

char x = '\377'; // Fine 
char y = '\400'; // Error: unclosed character literal 
+0

如果「unclosed character literal」錯誤消息來自官方的javac,那麼它將很好地適用於奇怪錯誤消息的列表。 –

+0

@Thorbjørn:我不認爲這很奇怪。它也不侷限於這種情況:''abc''也會這樣做。 –

相關問題