this

this
用法一:
public Dog(String name, int health, String type) {
this.name = name;
this.health = health;
this.type = type;
}
用在构造方法中或其他给属性赋值的方法中,用于区分成员变量和局部变量
使用this.属性名代表成员变量


this具体代表谁
在运行期间,哪个对象正在调用这个方法,那么this就指代当前这个对象,可以看成是“这个对象”
用法二:
//构造方法
public Dog(String name, int health, String type) {
this(name);
this.health = health;
this.type = type;
}

public Dog(){}

public Dog(String name) {
this.name = name;
}
在构造方法的第一句,使用this()的形式调用其他构造方法

原文地址:https://www.cnblogs.com/longmo666/p/13557252.html