0

I was writing code and using codepro tool for auditing, while I was writing a equals method, I encountered this kind of audit Missing identity check, I dont know how to correct it

my method code:

@Override
public boolean equals(Object o) {
    boolean result = false;
    if(o instanceof Coordinate){
        if(((Coordinate) o).x == x &&
                ((Coordinate) o).y == y){
            result = true;
        }
    }
    return result;
}

The description of the audit is this:

Description :Missing identity check

Explanation: The equals method should compare the identity of the receiver and the argument, returning true if they are the same.

Recommendation: 1. Add a test for object identity.

I dont know what means test for object identity, should I use unit test or something? Thank you for anyone helps me.

1 Answers1

3

it simply means you should check if the two objects are the same

  this == o;
akf
  • 38,619
  • 8
  • 86
  • 96