Given a list of String names, is it possible to call the proper method dynamically from a specific value?
In the example, the invokeMethod is made up but it would be what I need ideally. The first parameter is the method name to call and the second one the list of parameters.
class MethodPicker() {
val commands = listOf("foo", "tango")
fun messageReceiver() {
messageParam : String = "Hi stackoverflow!"
invokeMethod(commands.random(), messageParam) //HOW TO DO THIS IN KOTLIN?, the first parameter is the methodf name and the second one would be the parameters that the method receives
}
fun foo(message: String) {
println(message + "foo!")
}
fun tango(message: String) {
println(message + "tango!")
}
}