If all objects in the world are judged by direct equals, it will be okay. There are always some situations:
- Objects are placed in containers (such as hashset), and then equals is judged;
- Perform equals judgment between the object and the subclass of the inherited object;
- ......
[1] an incorrect equals method signature is defined.
No: Public Boolean euqals (pointer O );
Yes: Public Boolean equals (ObjectO );
[2] The equals method is reloaded, but the hashcode method is not reloaded at the same time.
No: No hashcode ()
Yes: Public intHashcode (){Return (41*(41 + getx () + Gety ());}
[3] equals definition based on changing word Fields
No: Public int;
Yes: PublicFinalInt;
[4] equals error definitions that do not meet the equivalence relationship
No: direct parent and sub-object comparison;
Yes: & this.Getclass ().Equals (that. getclass ())
Learning:
Http://blog.csdn.net/haoel/article/details/4282239
Http://www.artima.com/lejava/articles/equality.html