jeudi 12 novembre 2020

How get companion method reference (KFunction<>) by refelection

In Java it is possible to get a reference to static method in the following way (using reflection):

Method method = Class.forName("java.util.HashMap").getMethod("put", Object.class, Object.class);

In Kotlin it is possible to get a reference (type KFunctionX<>) to instance method in the following way (using reflection):

    var methodRef : KFunction0<Unit> = someInatance::instanceMethod

But when trying to get a companion method (using reflection) in the following way:

    var companionMethod = SomeJavaClass::someCompanionMethod

I'm getting an unresolved reference error





Aucun commentaire:

Enregistrer un commentaire