Kotlin reference document said this example is valid.
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() }
}
But in Android studio 3.0, it shows thin red line under it.clone()
. And error message is:
Type inference failed. Expected type mismatch.
Required:List<T>
Found:List<Any>
Why this example cannot be compiled?