Klitos Kyriacou
09/06/2023, 5:09 PMclass A {
override fun equals(other: Any?): Boolean {
return true
}
}
fun main() {
val a = A()
val b: A? = null
println(a == b) // It's always true, but IntelliJ warns it's always false
}Chris Lee
09/06/2023, 5:10 PMA to nullChris Lee
09/06/2023, 5:12 PMKlitos Kyriacou
09/06/2023, 5:12 PMtrue because of the overridden equals.Chris Lee
09/06/2023, 5:12 PMKlitos Kyriacou
09/06/2023, 5:18 PMa.equals(b), then it doesn't give that warning.
Also, a.equals(null) doesn't give a warning - which is correct, since a == null is not the same as a.equals(null) according to the language spec, but this only applies for the literal null. If it's a value that happens to be null, then a == b is always the same as a.equals(b) and therefore IntelliJ shouldn't give that warning.ephemient
09/06/2023, 5:38 PMequals does not satisfy the contractephemient
09/06/2023, 5:39 PMNever equal to null: for any non-null value,xshould return false.x.equals(null)
ephemient
09/06/2023, 5:39 PMJacob
09/06/2023, 6:22 PMprintln(b == a) print?Anton Mefodichev
09/08/2023, 10:27 AMKlitos Kyriacou
09/08/2023, 10:48 AMequals would satisfy the contract). It would be more important to see an inspection about equals not satisfying the contract, if that's possible. I made a comment on the ticket.