两个对象值相同x.equals(y) == true,但却可有不同的 hashCode,这句话对不对?

参考解答

不对。

  • 如果 x.equals(y) == true,那么一定有 x.hashCode() == y.hashCode()
  • 反之,如果x.hashCode() == y.hashCode(), x 不一定 equals y。

results matching ""

    No results matching ""