vendredi 8 novembre 2019

How can I create a condition to check the class used to create a KClass instance in Kotlin

In the code below I wanna know what was the class used to create a KClass instance. In the array case I found a way using java.IsArray, but how to do it for the other cases?

fun main() {

    val myKClassList = listOf(String::class, Array<String>::class, Int::class)

    myKClassList.forEach {
            if (it.java.isArray) println("Array")
            else if (??) println("String")
            else if (??) println("Int")
    }
}




Aucun commentaire:

Enregistrer un commentaire