Hello all
I tried looking for an explanations for this , but couldnt find.
Is it true that the only way my equals() method will work is when I compare fields using their "get.. ()" methods rather than the fields themselves ?
So this will NOT work :
Code:
public boolean equals(final Object other) {
if (!(other instanceof Address))
return false;
MyObject castOther = (MyObject) other;
return this.foo == castOther.foo;
}
and this will work :
Code:
public boolean equals(final Object other) {
if (!(other instanceof Address))
return false;
MyObject castOther = (MyObject) other;
return this.getFoo() == castOther.getFoo();
??
Thank you