I just came across a code using EqualsBuilder()
in equals
method. Is there any advantage of using it instead of writing (or generating from eclipse
Using ANYTHING except for your own implementation in equals() is GUARANTEED to be "worse" if you can use ... say a strictly unique ID.
If your ID is really unique you will most likely have the best, possible implementation with this, of course it needs to be polished quite a bit:
@Override
public boolean equals(Object other)
{
if(other instanceof MyClass)
{
MyClass obj = (MyClass)other;
return obj.getID() == this.getID();
}
else
return false;
}
Have a look at this, this and especially this