equals() をオーバーライドしているものの、hashCode() をオーバーライドしていないクラスを報告します (逆の場合にも対応しています)。
equals() または hashCode() をオーバーライドしているオブジェクト宣言も報告します。
これらは、Collection にクラスが追加される際に好ましくない動作を引き起こす場合があります。
例:
class C1 {
override fun equals(other: Any?) = true
}
class C2 {
override fun hashCode() = 0
}
object O1 {
override fun equals(other: Any?) = true
}
object O2 {
override fun hashCode() = 0
}
クイックフィックスを使用すると、クラスの場合は equals() または hashCode() がオーバーライドされ、オブジェクトの場合はこれらのメソッドが除去されます。
class C1 {
override fun equals(other: Any?) = true
override fun hashCode(): Int {
return javaClass.hashCode()
}
}
class C2 {
override fun hashCode() = 0
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
return true
}
}
object O1 {
}
object O2 {
}