in javasript, if we know the name of the method, we can pass it as parameter and call it like this
function foo(methodName){
methodName()
}
function doSomething(){
console.log("DO Something")
}
foo(doSomething)
I want to do something like this in kotlin, consider i have a class like this
Class DataModel{}
Class Foo (){
fun build(data:DataModel,val onThis:AnyMethod){
if(data.size>0){
val param = somevalue
onThis(param)
}
}
}
then in my Activity for example i have doThis method
class MainActivity : AppCompatActivity(){
//rest of code
fun doThis(param:Int){
Log.e("DO","THIS ${param}")
}
}
in my OnCreateView i want to call something like this
val a= new Foo()
a.build(data, doThis)
To do this, how my Foo Class should be?