Kotlin

Kotlin

Made by DeepSource

equals method always returns the same result KT-W1027

Bug risk
Major

The equals() method is used to compare two objects for equality. However, if the implementation of the method always returns a fixed value, such as true or false , it fails to accurately determine if the two objects are equal. This can lead to incorrect equality comparisons and unexpected behavior in the code.

To fix this issue, the logic inside the equals method should be modified to properly compare the two objects and determine their equality.

Bad Practice

override fun equals(other: Any?): Boolean {
  return true
}

Recommended

override fun equals(other: Any?): Boolean {
  return this === other
}

References