Pass interface as parameter in Kotlin

In Kotlin you can do :

test(object: Handler {
    override fun onComplete() {

    }
})

Or make a property the same way:

val handler = object: Handler {
    override fun onComplete() {

    }
}

And, somewhere in code: test(handler)


since your interface has only one function. you can convert it to SAM like this

fun interface Handler {
        fun onCompleted()
}

then you can just implement this interface using lambda instead and so reduce the overall written code. this is only possible in v1.4