// 寫法 1
return getClass().getName();
// 寫法 2
return this.getClass().getName();
完全相同。getClass() 是 Object 的 final 方法,**隱式調用者即當前實例 (this)**。
; 寫法 1
ALOAD 0 ; 載入 this
INVOKEVIRTUAL java/lang/Object.getClass ()Ljava/lang/Class;
; 寫法 2
ALOAD 0 ; 載入 this
INVOKEVIRTUAL java/lang/Object.getClass ()Ljava/lang/Class;
; 字節碼完全一致
編譯器自動插入 ALOAD 0 (this),**無任何性能差異**。
this.name = name;OuterClass.this.method()this(...)getClass() 與 this.getClass() **語義、字節碼、性能完全等價**。日常編碼**推薦省略 this**,僅在消除歧義時顯式使用。JVM 會自動處理隱式 this。