1

I have a method inside a class:

class Foo {
    fun bar()
}

And I want to pass the method bar to a third-party library method that takes a java.lang.reflect.Method argument:

   fun baz(Method method)

How do I do that? Ideally is there some function call f(Foo::bar) that takes a method reference and returns a Method?

1 Answer 1

3

With dependency org.jetbrains.kotlin:kotlin-reflect you can write

import kotlin.reflect.jvm.javaMethod

val method = Foo::bar.javaMethod
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.