爲什麼我可以使用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 –