So I have a setup like this:
interface A{
}
class B implements A{
public int hashCode() {
...
}
public boolean equals(final Object obj) {
...
}
}
class C implements A{
public int hashCode() {
...
}
public boolean equals(final Object obj) {
...
}
}
class D{
List<A> list = new ArrayList<A>();
}
I want to implement an overridden equals
method for class D that tests that the lists are equal, but for some reason whenever I try to implement that as this:
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final D other = (D) obj;
if (values == null) {
if (other.values != null)
return false;
}else if (!values.equals(other.values))
return false;
return true;
}
but I believe that this calls Object
's equals
method where it calls values.equals(other.values)
, because it is not behaving correctly.
What can I do to make D
's equals
method behave correctly?