# Can i call a function from a string?

**URL:** <https://discuss.kotlinlang.org/t/can-i-call-a-function-from-a-string/19620>\
**Category:** Uncategorized\
**Created:** [October 23, 2020, 12:06pm UTC](https://discuss.kotlinlang.org/t/can-i-call-a-function-from-a-string/19620 "2020-10-23T12:06:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![absoluterookie](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@absoluterookie](https://discuss.kotlinlang.org/u/absoluterookie)\
**Post date:** [October 23, 2020, 12:06pm UTC](https://discuss.kotlinlang.org/t/can-i-call-a-function-from-a-string/19620/1 "2020-10-23T12:06:47Z")

</div>

Example:

```auto
fun appSetOnA(whatever)
fun appSetOnB(whatever)

var caller:String ="OnA"

//call
WHATTODO+"appSet"+caller
```

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

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [October 23, 2020, 12:41pm UTC](https://discuss.kotlinlang.org/t/can-i-call-a-function-from-a-string/19620/2 "2020-10-23T12:41:26Z")

</div>

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`.
