面试题答案
一键面试class Person(val age: Int) : Comparable<Person> {
override fun compareTo(other: Person): Int {
return this.age - other.age
}
}
fun main() {
val ageRange = 20..30
val personList = listOf(
Person(18),
Person(22),
Person(25),
Person(35)
)
val filteredList = personList.filter { it.age in ageRange }
println(filteredList.map { it.age })
}