From my understanding, if a Kotlin method requires one argument and that argument is an interface with a single method, I can pass in a lambda expression instead (as illustrated by numerous online tutorials using setOnClickListener
and stuff like that). However, compiling the following code:
interface I {
fun ha()
}
class C() {
fun set(i: I) { i.ha() }
}
fun main(args: Array<String>) {
val c = C()
c.set { println("Hi") }
}
results in: error: type mismatch: inferred type is () -> Unit but I was expected
.
Did I missing something?