关于java中重写.equals()方法的问题
ringa_lee
ringa_lee 2017-04-18 10:44:44
0
2
878
ringa_lee
ringa_lee

ringa_lee

reply all(2)
阿神

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() 方法
    }   
}
Peter_Zhu

Every time a member method is called, it will be passed in implicitlythis对象,编译器会去给getClass() 加上this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template