If a Kotlin function invocation reifies a primitive, say Int
, the 'passed' class is that for the boxed primitive, not the unboxed version.
inline fun <reified T> reify() = T::class
@Test fun reified_type_doesnt_match_for_primitive() {
assertNotEquals(Int::class, reify<Int>())
assertNotEquals(Int::class.java, reify<Int>().java)
assertNotEquals<Any>(Int::class, reify<Int?>())
val nullableInt: Int? = 42
assertNotEquals(nullableInt!!.javaClass.kotlin, reify<Int>())
assertEquals<Any>(java.lang.Integer::class.java, reify<Int>().java)
}
@Test fun reified_type_matches_for_class() {
assertEquals(String::class, reify<String>())
}
Is this a bug?