Copyright: original works, for permission to reproduce, reprint, please be sure to hyperlink to the original source of the article indicated, author information and this statement. Otherwise held liable. http://zhangjunhd.blog.51cto.com/113473/71571  
The following summary from the "Effective Java". 1. When you need to override equals () When a class has its own unique "logical equal" concept (as opposed to the concept of object identity.) 2. Design equals () [1] using the instanceof operator to check the "argument of whether the correct type." [2] For each class a "key field", to check the arguments in the current object in the domain and the corresponding field values. [2.1] for nonfloat and double primitive type type field, use the == comparison; [2.2] for object reference domain, recursive calls equals method; [2.3] for float field, use the Float. FloatToIntBits (afloat) is converted to int, then use the == comparison; [2.4] for the double domains, use the Double. DoubleToLongBits (adouble) converted to int, then use the == comparison; [2.5] for the array of domain, call Arrays.equals method. 3. When override equals (), you always want to rewrite the hashCode () According to a class equals method (rewritten), there may be two distinct instances are equal in terms of logic, but, according Object.hashCode methods, they are only two objects. Therefore, a violation of "equal objects must have equal hash codes." 4. Design hashCode () [1] to a nonzero constant value, such as 17, the result stored in the int variable; [2] For each of the key objects in the domain f (equals methods that consider each domain): [2.1] boolean type, calculated (f? 0: 1); [2.2] byte, char, short type, calculate (int); [2.3] long type, calculate (int) (f ^ (f>>> 32)); [2.4] floattype, calculated Float. FloatToIntBits (afloat); [2.5] double type, calculated Double. DoubleToLongBits (adouble) to get a long, then the implementation of [2.3]; [2.6] object reference, recursively call its hashCode method; [2.7] array domain, each element of which is called its hashCode method. [3] to calculate the hash code above saved to int variable c, then run result = 37 * result + c; [4] return result. 5. Example Following the design of the class to follow the above principles, the class overrides the equals () and hashCode ().

Copyright: original works, for permission to reproduce, reprint, please be sure to hyperlink to the original source of the article indicated, author information and this statement. Otherwise held liable. http://zhangjunhd.blog.51cto.com/113473/71571  
The following summary from the "Effective Java". 1. When you need to override equals () When a class has its own unique "logical equal" concept (as opposed to the concept of object identity.) 2. Design equals () [1] using the instanceof operator to check the "argument of whether the correct type." [2] For each class a "key field", to check the arguments in the current object in the domain and the corresponding field values. [2.1] for nonfloat and double primitive type type field, use the == comparison; [2.2] for object reference domain, recursive calls equals method; [2.3] for float field, use the Float. FloatToIntBits (afloat) is converted to int, then use the == comparison; [2.4] for the double domains, use the Double. DoubleToLongBits (adouble) converted to int, then use the == comparison; [2.5] for the array of domain, call Arrays.equals method. 3. When override equals (), you always want to rewrite the hashCode () According to a class equals method (rewritten), there may be two distinct instances are equal in terms of logic, but, according Object.hashCode methods, they are only two objects. Therefore, a violation of "equal objects must have equal hash codes." 4. Design hashCode () [1] to a nonzero constant value, such as 17, the result stored in the int variable; [2] For each of the key objects in the domain f (equals methods that consider each domain): [2.1] boolean type, calculated (f? 0: 1); [2.2] byte, char, short type, calculate (int); [2.3] long type, calculate (int) (f ^ (f>>> 32)); [2.4] floattype, calculated Float. FloatToIntBits (afloat); [2.5] double type, calculated Double. DoubleToLongBits (adouble) to get a long, then the implementation of [2.3]; [2.6] object reference, recursively call its hashCode method; [2.7] array domain, each element of which is called its hashCode method. [3] to calculate the hash code above saved to int variable c, then run result = 37 * result + c; [4] return result. 5. Example Following the design of the class to follow the above principles, the class overrides the equals () and hashCode ().
