jeudi 1 février 2018

How to distinguish between a class and an interface in Kotlin using KClass reflection

I am using Kotlins KClass to find classes by name like this:

val i: KClass<*> = Class.forName("SampleClass").kotlin

However, I want to omit interfaces. So far I am distinguishing interfaces from classes by the constructor.

val i: KClass<*> = Class.forName(input).kotlin

if (i.constructors.isEmpty()){
    println("This is an interface")
}else{
    println("This is a class")
}

I don't think that it is very clean. I am looking for something along the lines of

i.isInterface

Does something like this exist?





Aucun commentaire:

Enregistrer un commentaire