报告覆盖 equals() 方法但不覆盖 hashCode() 方法的类,反之亦然。将类添加到 CollectionHashMap 时,这可能会导致问题。

快速修复为不存在的方法生成默认实现。

示例:


class StringHolder {
  String s;

  @Override public int hashCode() {
    return s != null ? s.hashCode() : 0;
  }
}

在应用快速修复后:


class StringHolder {
  String s;

  @Override public int hashCode() {
    return s != null ? s.hashCode() : 0;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof StringHolder)) return false;

    StringHolder holder = (StringHolder)o;

    if (s != null ? !s.equals(holder.s) : holder.s != null) return false;

    return true;
  }
}