How to pass a function in android using Kotlin . I can able to pass if i know the function like :
fun a(b :() -> Unit){
}
fun b(){
}
I want to pass any function like ->fun passAnyFunc(fun : (?) ->Unit){} 
You can use anonymous function or a lambda as follows
fun main(args: Array<String>) {
    fun something(exec: Boolean, func: () -> Unit) {
        if(exec) {
            func()
        }
    }
    //Anonymous function
    something(true, fun() {
        println("bleh")
    })
    //Lambda
    something(true) {
        println("bleh")
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With