Is it possible to get a method by a string name in...
# korge
m
Is it possible to get a method by a string name in kotlin? It would work with
Copy code
javaClass.enclosingMethod.name
in java, but java is not available and I don't want to just run on the jvmMain, I want to have commonMain. So is there any way to get and execute a method with just its name as string?
t
You can do it with Koltin Reflections. But have to make sure you also included the ``kotlin-reflect.jar``. StackOverflow
Copy code
obj::class.members.firstOrNull { it.name == "methodName" }?.call(argument1, argument2, ...)
More Info: kotlinlang.org - reflection
m
Thank you. How can I include the kotlin-reflect.jar in the korge-build.gradle.kts?
On kotlinlang.org there is dependencies { implementation("org.jetbrains.kotlinkotlin reflect1.4.21") }
But where do I implement this in the gradle of korge?