new question here:
So, in my homework at the university, I have to redefine the object class method for the new class I created.
The new class is the “Product”, each product has an attribute “id”, which is unique. So this is how I redefined it:
@Override
public boolean equals(Object obj) {
final Product other = (Product) obj;
if (id != other.id)
return false;
return true;
}
The fact is that this is 1.5 out of 10 points, and this made me suspiciously so simple. So I started the search, and I found things like:
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Product other = (Product) obj;
if (id != other.id)
return false;
return true;
}
Which makes no sense to me, because I think the latter, if you check all the other ifs restrictions. What do you guys think? What is the best way to override this method?
Thank!
Iñaki source
share