The difference between "equals" and "==" in

Compare also equals the address, but when used, it is usually rewritten equals () method, and thus is a "value" for comparison

Java language requirements for equals () below, these requirements must be followed:
  Symmetry: If x.equals (y) returns is "true", then y.equals (x) should return a "true".
  Reflex: x.equals (x) Returns must be "true".
  Sexual analogy: If x.equals (y) returns is "true", and y.equals (z) returns is "true", then z.equals (x) should return a "true".
  Consistency: If x.equals (y) returns is "true", as long as the x and y have the same content, whether you repeat x.equals (y) the number of times, returns are "true".
  In any case, x.equals (null), always returns a "false"; x.equals (and a different type of object x) always returns a "false".
  This is five points above methods, guidelines must be followed to rewrite equals (), if the violation unexpected results occur, please be sure to follow

  hashCode method returns the object's default address, String, Integer and other package types rewritten it returns an integer
  of the integer values from the current coded value for each letter of the string. publicity following
  public int hashCode () {
    return "ABCDE" .hashCode ();
  }

"==" comparison is the address,

Guess you like

Origin www.cnblogs.com/xinchen01/p/10969238.html