Can i call a function from a string?


fun appSetOnA(whatever)
fun appSetOnB(whatever)

var caller:String ="OnA"


I guess not right?
The point is, i got about 20 different functions that returns me an number.
And insetad of go through a if, switch or when story, would be nice if i could do it that way.

Solutions? Link to a description would be nice to

Reflection might be a way, but it’s often discoureged.

Probably there’s a way better solution given more context. Maybe these 20 functions are not that far apart and you can have some enum decribing the behavior and slim that down to a function which takes an enum and returns an Int.

1 Like