jeudi 23 mars 2017

Kotlin Reflection - Check if property has type

I want to iterate over all fields in one of my classes, filter for annotated ones and then check if the field has one specific type.
All I found was field.returnType.isSubtype(other: KType) but I don't know how to get the KType of my other class.

Here is my code so far:

target.declaredMemberProperties.forEach {
    if (it.findAnnotation<FromOwner>() != null) {
        if ( /*  it.returnType is Component <- Here I need some working check   */ ) {

            // do stuff
         } else {

            // do ther stuff
         }
    }
}





Aucun commentaire:

Enregistrer un commentaire