As the equals method’s parameter is typed as generic Any?, any type of object may be passed to it. The method implementation should not assume it will only be used to test objects of its own class type. It must instead check the parameter’s type.

Noncompliant Code Example

override fun equals(other: Any?): Boolean {  // Noncompliant
  val mc = other as MyClass
  // ...
}

Compliant Solution

override fun equals(other: Any?): Boolean {
  if (other?.javaClass != this.javaClass)
    return false

  val mc = other as MyClass
  // ...
}