【发布时间】:2018-05-15 07:10:06
【问题描述】:
Kotlin 参考文档说这个例子是有效的。
https://kotlinlang.org/docs/reference/generics.html#upper-bounds
fun <T> cloneWhenGreater(list: List<T>, threshold: T): List<T>
where T : Comparable<T>,
T : Cloneable {
return list.filter { it > threshold }.map { it.clone() }
}
但在 Android Studio 3.0 中,它在it.clone() 下显示细红线。错误信息是:
类型推断失败。预期的类型不匹配。
必填:List<T>
找到:List<Any>
为什么这个例子不能编译?
【问题讨论】:
标签: android android-studio kotlin android-studio-3.0