lundi 24 août 2020

How to invoke a kotlin method by reflection?

Here is my code:

class Repository {
    companion object {
        suspend fun clientList(clientListRequest: HashMap<String, String>): List<ClientEntity> {
            var result = NetConfig.api.clientList(clientListRequest).rows
            if (result == null) return emptyList()
            return result
        }
    }

}

Try to invoke:

     var method: Method? = null
     for (i in 0..Repository.javaClass.declaredMethods.size) {
         if (Repository.javaClass.declaredMethods[i].name.equals(methodName)) {
            method = Repository.javaClass.declaredMethods[i]
            log("${method}")
              break
            }
       }
     method?.isAccessible = true

The log prints:

"public final java.lang.Object com.**.commonlib.net.Repository$Companion.clientList(java.util.HashMap,kotlin.coroutines.Continuation) "

As you can see, I don't declare a parameter which type is Continuation. I'm confused what is it and how to invoke the method?





Aucun commentaire:

Enregistrer un commentaire