5-2 equal getClass or instanceOf
如果是想通过严格的类名判断就使用 getClass 如果是子父类某些属性相等就视为相等就使用instanceOf /* public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || this.getClass() != obj.getClass()) { return false; } Father father = (Father) obj; return (str != null && str.equals(father.str)); }*/ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || !(obj instanceof Father)) { return false; } Father father = (Father) obj; return (str != null && str.equals(father.str)); }