In Android+Kotlin both of the following syntaxes are valid
view.setOnClickListener(this) and view.setOnClickListener {} I have been trying to achieve this syntax for my custom functional interface without any success. Here is what I have tried so far
interface OnClickListener {
fun onClick(str: String)
}
class Test {
fun setClickListener(listener: OnClickListener) {
listener.onClick("")
}
}
fun main() {
val test = Test()
test.setClickListener { str ->
}
}
in the above snippet code in main() fails to compile as it needs an anonymous object of OnClickListener class. How can I achieve the same syntax for client code as with the original OnClickListener?