阿神2017-04-18 10:46:44
is the getClass() method of the current object.
Using methods or properties of the current object within the current object can be ignored this
,除非有参数名重复,才需要特别指定 this
class Demo {
private String id;
private String name;
public Demo(String id, String name){
this.id = id; // 参数与字段名重复,所以需要指定 this
this.name = name;
}
public Demo(String username) {
name = username; // 这里的name 就是当前对象的name
id = getClass().toString(); // 这里的 getClass() 也是当前对象的getClass() 方法
}
}
天蓬老师2017-04-18 10:46:44
Every time a member method is called, it will be passed in implicitlythis
对象,编译器会去给getClass()
加上this