【发布时间】:2020-01-24 10:51:51
【问题描述】:
这是我的代码不起作用:
val people = listOf(Person("Tarun", 28), Person("Shyam", 25), Person("Pushpraj", 27))
people.maxBy { Person::age }
上述代码出现的错误:
Type parameter bound for R in inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R): T?
is not satisfied: inferred type KProperty1<Person, Int> is not a subtype of Comparable<KProperty1<Person, Int>>
工作代码:
val people = listOf(Person("Tarun", 28), Person("Shyam", 25), Person("Pushpraj", 27))
people.maxBy { it.age }
无法理解这里的问题。
【问题讨论】: