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

ringa_lee

全部回覆(2)
阿神

是目前物件的 getClass()方法。
在目前物件內使用目前物件的方法或屬性可以忽略 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

每次呼叫成員方法的時候都會隱式傳入this对象,编译器会去给getClass() 加上this

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!