'Kotlin SAM interface and method reference
I am a bit confused why I can do the following
val outputter1: (s: String) -> Unit = ::println
but when I do
val outputter2: Outputter = ::println
given
fun interface Outputter {
fun output(output: String)
}
I get a compilation error
None of the following functions can be called with the arguments supplied.
println() defined in kotlin.io
println(Any?) defined in kotlin.io
...
Shouldn't method references translate to SAM inteface types as well as Function types?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
