类 java.lang.Object

final method

  • public final Class<?> getClass()
  • public final void notify()
  • public final void notifyAll()
  • public final void wait(long timeout)throws InterruptedException
  • public final void wait(long timeoutint nanos) throws InterruptedException
  • public final void wait() throwsInterruptedException

class method

equals

return (this == obj);

重写规范:

  • reflexive

    x.equals(x) = true (x != null)

  • symmetric

    x.equals(y) = true => y.equals(x) = true(x != null)

  • transitive

    x.equals(y) = true && y.equals(z) = true => x.equals(z) = true(x != null)

  • consistent

    x.equals(y) = true => x.equals(y) = true

  • x.equals(null) = false (x != null)

Java核心编程内建议

public boolean equals(Object otherObj){
   if(this == other) return true;
   if(otherObj == null) return false;
   //if(this.getClass != otherObj.getClass()) return false;
   //if(!(otherObj instanceof ClassName)) return false;
   //ToDo Compare Class Field
}

toString:

return getClass().getName() + "@" + Integer.toHexString(hashCode());