注釋中的代碼是否會被執行呢?我毫不猶豫的回答,不回執行。然而,是真的可能會執行。請往下看:
// 猜猜結果會是什么呢?
public class Test01 { public static void main(String[] args) { String a = "Hello zss!"; // \u000d a = "foolish opt!"; System.out.println(a); } }
輸出結果是:foolish opt!
為什么會如此呢?
因為 \u000d 是unicode編碼中的換行--“\r” java編譯器會處理unicode字符。編譯后等於如下情況:
String a = "Hello zss!"; a = "foolish opt!"; System.out.println(a); String b = "a \\\\u000d b"; System.out.println(b);