Rich Rich - 1 year ago 43
Java Question

Getting a reference to a Kotlin function as a Java Method

I have a Java method that takes a


void doSomethingWithMethod(Method m) {

And I have a Kotlin class that contains a function:

class MyClass {

fun myFunction() : List<Something> {


I can get a reference to the function with
, but I don't see a way to pass it into the
method. Is there an equivalent to the
property that can be applied to a Kotlin class reference to get its Java equivalent?

If not, is there a workaround?

import kotlin.reflect.jvm.javaMethod

val method = MyClass::myFunction.javaMethod

The javaMethod property is not part of the standard Kotlin library, but is part of the official kotlin-reflect.jar. It can be added through Maven with the following dependency: