title: Equals overloading in Kotlin
body: <p>I was trying to overload <code>compareTo</code> and <code>equals</code> operators for my class.</p>
  
  <p>There is no problem with compare operator. It works well both as member and as an extension function.</p>
  
  <p>The equals operator must be a member and override equals fun.</p>
  
  <pre><code>class MyClass {
      companion object {
          private val NUMBER: Int = 5
  
          operator fun compareTo(value: Int) = NUMBER - value
  
          override operator fun equals(other: Any?) =
                  when (other) {
                      is Int -&gt; NUMBER == other
                      else -&gt; throw Exception("")
                  }
      }
  }
  
  fun test() {
      if (MyClass &lt; 10) {
          //ok
      }
  
      //Operator '==' cannot be applied to 'MyClass.companion' and kotlin.Int
      if (MyClass == 5) {
      }
  }
  </code></pre>
  
  <p><strong>Edit:</strong> How to overload '==' properly?</p>