I have a card from KClassto Int. Then I have a function that is of type reified generic. Then I expected the following situation to give me IntrelatedBoolean::class
val kclassToInt = mapOf(Boolean::class to 1, Byte::class to 1, Short::class to 2)
inline fun <reified T> myExpectations() =
assertEquals(1, kclassToInt.getRaw(T::class), "Why doesn't it work? :'(")
Welcome Why doesn't it work? :'(. Expected <1>, actual <null>.from calling him like myExpectations<Boolean>().
Then I tried to use .javaoff, so I used Java Class, not Kotlin KClass.
val classToInt = mapOf(Boolean::class.java to 1, Byte::class.java to 1, Short::class.java to 2)
inline fun <reified T : Any> anotherExpectation() =
assertEquals(1, classToInt.getRaw(T::class.java))
This time I was again met with a statement error: java.lang.AssertionError: Expected <1>, actual <null>.
Finally, I tried using .javaClass, not .java:
val javaClassToInt = mapOf(Boolean::class.javaClass to 1, Byte::class.javaClass to 1, Short::class.javaClass to 2)
inline fun <reified T> pleaseWork() =
assertEquals(1, javaClassToInt.getRaw(T::class.javaClass))
This time it was really strange. I was greeted as follows: java.lang.AssertionError: Expected <1>, actual <2>.Everyone seems .javaClassto relate to KClassImpl.
, , , .qualifiedName:
val qnToInt = mapOf(Boolean::class.qualifiedName to 1, Byte::class.qualifiedName to 1, Short::class.qualifiedName to 2)
inline fun <reified T> iKnowItWorks() =
assertEquals(1, qnToInt.getRaw(T::class.qualifiedName))
, , : https://github.com/Jire/kotmem/blob/master/src/main/kotlin/org/jire/kotmem/Process.kt