I was wondering how equals method in Object class works. This is the implementation of the method.
public boolean equals(Object obj) {
return (this == obj);
}
where its evident that equals method is using ==
.
So,now when I am comparing two objects a and b, if a happens to be null, it doesn't throw any exception. But a.equals(b)
, throws NPE, why?