2
我發現不是默認,默認參數值的奇案:如何使參數默認?
class Dog
class DogHouse(dog: Dog)
inline fun <T: Any, A: Any> build(sth: String = "", call: (A) -> T) {}
fun main(args: Array<String>) {
build(call = ::DogHouse)
build(::DogHouse) // This line fails to compile
}
的編譯錯誤:
Error:(11, 5) Kotlin: Type inference failed: inline fun <T : Any, A : Any> build(sth: String = ..., call: (A) -> T): Unit
cannot be applied to
(KFunction1<@ParameterName Dog, DogHouse>)
Error:(11, 11) Kotlin: Type mismatch: inferred type is KFunction1<@ParameterName Dog, DogHouse> but String was expected
Error:(11, 21) Kotlin: No value passed for parameter call