is it possible to access a property or function by...
# announcements
h
is it possible to access a property or function by string containing its name at run time, like in JavaScript?
k
Do you mean in Kotlin-JS? If so take a look at
js(...)
. There's also the reflection API, https://kotlinlang.org/docs/reference/reflection.html
h
I'm developing for Android
k
Then reflection should work. Beware that "finding a function by name at runtime" is often a sign of bad design.
h
how do you use reflection to do that? I see that you can get references to properties and functions, but it doesn't show a way to use a string to specify their names
k
You'd loop over all of the functions of a class and check for a name match.
h
how do you get a list of functions of a class?
h
all right, thanks!
👍 1