https://kotlinlang.org logo
#korge
Title
# korge
m

Michael Sigl

01/30/2021, 12:14 AM
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

tobsef

01/30/2021, 10:16 AM
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

Michael Sigl

01/30/2021, 11:05 AM
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?
2 Views