jbnizet
05/16/2016, 1:12 PMfun search(name: String): List<Exercise> {
return allExercises.stream()
.filter { it.title.contains(name, ignoreCase = true) }
.collect(toList())
}
(where allExercises
is a property of type List<Exercise>
)
That doesn’t compile: I get
Error:(27, 29) Kotlin: Type inference failed. Expected type mismatch: inferred type is (MutableList<in Exercise!>..List<Any?>?) but List<Exercise> was expected
.
I know I could just use the native Kotlin functional methods, but how to make this compile? All I found was
@Suppress("UNCHECKED_CAST")
fun search(name: String): List<Exercise> {
return allExercises.stream()
.filter { it.title.contains(name, ignoreCase = true) }
.collect(toList()) as List<Exercise>
}