java 中 this 關鍵字的3中使用場景
1、參數賦值時解決歧義
String name = "bob" ;
public void setName(name){
this.name = name
}
2、方法中返回自身引用
public class Person{
public Person getPerson(){
return this;
}
}
3、構造器中調用同類的另一個構造器
this("hello")
只能掉用一次,並且在第一句。
參考資料:《java編程思想》5.4 節 this關鍵字