Back to Intellij Community

RecursiveEqualsCall

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/RecursiveEqualsCall.html

2025.3-rc-2654 B
Original Source

Reports recursive equals(==) calls.

In Kotlin, == compares object values by calling equals method under the hood. ===, on the other hand, compares objects by reference.

=== is commonly used in equals method implementation. But === may be mistakenly mixed up with == leading to infinite recursion.

Example:

class X {
      override fun equals(other: Any?): Boolean {
          if (this == other) return true
          return false
      }
  }

After the quick-fix is applied:

class X {
      override fun equals(other: Any?): Boolean {
          if (this === other) return true
          return false
      }
  }