SAM
SAM conversion on Kotlin Interfaces
由于 Kotlin 中拥有完整的函数类型,所以 SAM 是为 Java 接口设计的
具体细节差异如下:
interface GenericCon<T> {fun accept(t: T)}@Testfun lam() {Consumer<Int> { println(it) }// 编译错误,无法正常运行GenericCon<Int>{ println(it) }}
SAM conversion on Kotlin Interfaces
由于 Kotlin 中拥有完整的函数类型,所以 SAM 是为 Java 接口设计的
具体细节差异如下:
interface GenericCon<T> {fun accept(t: T)}@Testfun lam() {Consumer<Int> { println(it) }// 编译错误,无法正常运行GenericCon<Int>{ println(it) }}
让时间为你证明