I've got a Node<T>
with an equals()
method:
public boolean equals(Node<T> other) {
if (this == other)
return true;
if (other == null)
return false;
if (!obj.getClass().equals(other.getObject().getClass()))
return false;
return obj.equals(other.getObject());
}
I only care if the object held in my node is equal to the object held in the other node (because two equal objects can be held in different positions in my list).
The object I'm holding is a Token
. The Token.equals()
method works while my Node.equals()
method does not:
public class TokenEqualityTest {
public static void main(String[] args) {
Token t = new Token(0);
Token q = new Token(0);
System.out.println("t.equals(q): " + t.equals(q));
Node<Token> tnode = new Node<Token>(null, null, t);
Node<Token> qnode = new Node<Token>(null, null, q);
System.out.println("tnode.equals(qnode): " + tnode.equals(qnode));
}
}
which prints:
t.equals(q): true
tnode.equals(qnode): false
If I put a breakpoint at Token.equals()
and run the eclipse debugger, my code stops once (at t.equals(q)
). This indicates that Node<Token>.equals()
does not call Token.equals
, and I have verified that the debugger does step through the line return obj.equals(other.getObject());
.