title: Kotlin class equality fails
body: <p>The following snippet shows the result of testing equality of Kotlin <code>KClass</code> references obtained from different sources. Their string representations are the same. But their java classes are different. Expected that <code>c</code>, <code>c0</code> and <code>c1</code> are equal. But for some reason they aren't. </p>
  
  <p>Is there some nuance or it's a bug? If it's not a bug what is the reliable way to test equality of <code>KClass</code>es?</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;) {
      val c = Int::class
      fun test(v0: Any, v1: Any) {
          val c0 = v0.javaClass.kotlin
          val c1 = v1.javaClass.kotlin
          println("c= $c;  c0= $c0;  c1= $c1") // c= class kotlin.Int;  c0= class kotlin.Int;  c1= class kotlin.Int
          println("c= ${c.java};  c0= ${c0.java};  c1= ${c1.java}") // c= int;  c0= class java.lang.Integer;  c1= class java.lang.Integer
          println("c = c0? ${c == c0};  c0 = c1? ${c1 == c0}") // c = c0? false;  c0 = c1? true
      }
      test(11, 22)
  }
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>The workaround is to use <code>KClass.javaObjectType</code> method. </p>
  
  <p>The docs says:</p>
  
  <blockquote>
    <p>Returns a Java Class instance corresponding to the given KClass instance. In case of primitive types it returns corresponding wrapper classes.</p>
  </blockquote>
  
  <p>I.e. <code>c.javaObjectType == c1.javaObjectType</code> is true</p>
  
  <p>But it doesn't justifies why <code>KClass</code>es having same string representation are different. At least it's confusing. And it's good idea to note about that in docs.</p>