@ Data rewrittenequalshashCodemethods

protected boolean canEqual(Object other) {
    return other instanceof DataExample;
  }
  
  @Override public boolean equals(Object o) {
    if (o == this) return true;
    if(! (oinstanceof DataExample)) return false;
    DataExample other = (DataExample) o;
    if(! other.canEqual((Object)this)) return false;
    if (this.getName() == null? other.getName() ! =null:!this.getName().equals(other.getName())) return false;
    if (this.getAge() ! = other.getAge())return false;
    if (Double.compare(this.getScore(), other.getScore()) ! =0) return false;
    if(! Arrays.deepEquals(this.getTags(), other.getTags())) return false;
    return true;
  }
  
  @Override public int hashCode(a) {
    final int PRIME = 59;
    int result = 1;
    final long temp1 = Double.doubleToLongBits(this.getScore());
    result = (result*PRIME) + (this.getName() == null ? 43 : this.getName().hashCode());
    result = (result*PRIME) + this.getAge();
    result = (result*PRIME) + (int)(temp1 ^ (temp1 >>> 32));
    result = (result*PRIME) + Arrays.deepHashCode(this.getTags());
    return result;
  }
Copy the code

It will cause the same object, the property value to change, the hashCode to be different. You get an error on a Map, Set, etc. Such as

Person p = new Person(1);
HashSet<Person> set = new HashSet<>();
set.add(p);
p.setAge(2);
set.add(p); // add succeeds, set.size() = 2
Copy the code