为什么我可以使用Lambda作为java.lang.Thread
类,但不能用于MyThread
?为什么Lambda表达式对于Kotlin和Java类表现不同?
interface MyRunnable{
fun run()
}
class MyThread(runnable : MyRunnable){
}
fun test(){
Thread({}) // All Alright
MyThread({}) //Exception. Type mismatch <<-- Why ?
}
链接来检查这个例子:在SAM conversionshttps://try.kotlinlang.org/#/UserProjects/tbs79qfkh50psp7r3qrdrinrmt/sfkpjq1bjvg4r6d5rmnu6mp4a8
相同:https://stackoverflow.com/questions/44190468 –
相同:https://stackoverflow.com/questions/44189319 –