java - Dont understand this implementaion of equals method -


few days ago professor showed how implement equals method , many more.

this code example equals method , dont understand 1 part:

public boolean equals(object obj) {     if (this == obj)         return true;     if (obj == null)         return false;     if (getclass() != obj.getclass())         return false;     knjiga other = (knjiga) obj;     return objects.equals(isbn,other.isbn); } 

in first if statement check if (current object) has same reference object obj ( that's == operator ? compare 2 references)

and if got same reference return true ? never check other fields, such isbn , many more put because method never come part if these 2 objects have same reference.

in point of view method similar double equals operator cuz either of these 2 wont check fields, reference ?

if 2 objects being compared have same reference, same object, , there's no point in comparing else. can return true , save comparisons.

the other properties guaranteed equal in case.


Comments