I\'m having a problem with getting an ArrayList to correctly use an overriden equals. the problem is that I\'m trying to use the equals to only test for a single key field, and
There are two errors in your code.
First: The "contains" method called on "objectList" object should pass a new InnerClass object as the parameter.
Second: The equals method (should accept the parameter as Object, and is correct) should handle the code properly according to the received object. Like this:
@Override
public boolean equals (Object in) {
System.out.println("reached here");
if(in == null) {
return false;
}else if( in instanceof InnerClass) {
String inString = ((InnerClass)in).testKey;
return testKey == null ? false : testKey.equals(inString);
}else {
return false;
}
}