我什么時(shí)候應(yīng)該在課堂上使用“這個(gè)”?我知道this引用當(dāng)前對象。但我不知道什么時(shí)候我才真正需要使用它。例如,如果我使用x而不是this.x在某些方法上?可能是x將引用被考慮的方法的局部變量嗎?我指的是變量,只有在這種方法中才能看到。關(guān)于this.method()?我能用一下嗎?我該用它嗎。如果我只是用method(),默認(rèn)情況下,它不會(huì)應(yīng)用于當(dāng)前對象嗎?
3 回答

嗶嗶one
TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
this
public class Outer { protected int a; public class Inner { protected int a; public int foo(){ return Outer.this.a; } public Outer getOuter(){ return Outer.this; } }}

月關(guān)寶盒
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊
this
this
添加回答
舉報(bào)
0/150
提交
取消