Escape Rout

public class EscapeRout {
    public static void main(String...strings){
        System.out.println("a/u0022.length() + /u0022b".length());
    }
}

這一行會打印什麼呢?

2

實質上第三行編譯的結果是:
System.out.println(“a”.length() + “b”.length());

如果將這行改成:
System.out.println("a/".length() + /"b".length());
那麼打印的結果是:

16

In summary, prefer escape sequences to Unicode escapes in string and character literals. Unicode escapes can be confusing because they are processed so early in the compilation sequence. Do not use Unicode escapes to represent ASCII characters. Inside of string and character literals, use escape sequences; outside of these literals, insert ASCII characters directly into the source file.

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