jeudi 16 mai 2019

Method threw 'java.lang.IllegalArgumentException' exception. Cannot evaluate $Proxy0.toString()

I'm trying to load an interface using reflection with this code :

val clazz : Class<Client> = Client::class.java
val classLoader = clazz.classLoader
val invocationHandler = ProviderInvocationHandler()

Proxy.newProxyInstance(classLoader, arrayOf(clazz), invocationHandler)

Here is my Client interface :

interface Client {
    fun getCustomer(id: String)
}

And my invocation handler :

private class ProviderInvocationHandler : InvocationHandler {

    override fun invoke(proxy: Any?, method: Method?, args: Array<out Any>?): Any {
        Log.d("Reflection", "Invocation handler")

        return method!!.invoke(proxy, args)
    }
}

Nothing append when I execute this code and invoke from the handler method is never call. But if I assign the value of Proxy.newProxyInstance in a variable, in my debugger I see this : Method threw 'java.lang.IllegalArgumentException' exception. Cannot evaluate $Proxy0.toString()

Don't understand why this exception is raised





Aucun commentaire:

Enregistrer un commentaire