Reputation: 35
I think that CASE 2 should also return true. Is this behavior correct?
// CASE 1
Int::class.javaPrimitiveType!!.kotlin == Int::class.javaObjectType.kotlin // true
// CASE 2
Int::class.javaPrimitiveType!!.kotlin === Int::class.javaObjectType.kotlin // false
Upvotes: 1
Views: 542
Reputation: 32776
This behavior is correct. KClass
instances for a primitive type and the corresponding object type are equal (==), however they're created from different java.lang.Class
instances and since .java
always returns the original Class
instance the KClass
was constructed from, it wouldn't be possible for them to also be identical (===).
Upvotes: 7
Reputation: 83852
Short answer: yes.
Long answer: of course it’s hard to tell what the intended behaviour should be as nobody of us was involved in making that decision, or writing that code. However, I don’t think that it’s really a requirement that these two objects are in fact the same object; equality is sufficient, reference equality is not required here.
Upvotes: 0