Tips--java

Difference between "==null" and ".equals(null)"

== reference compare;

.equals() is a method;

notification: while sample = null; sample.equals(null) will throw NullPointerException.

refer topic links: topics link

 

Object.equals() code:

public boolean equals(Object obj) {
        return (this == obj);
}

 所以除非被继承类扩展,equals方法和“==”是等价了。

 

posted @ 2016-01-25 15:45  GAN_REPLACE  阅读(116)  评论(0)    收藏  举报