Hello. I’m a Kotlin newbie, and I’m trying to use ...
# getting-started
j
Hello. I’m a Kotlin newbie, and I’m trying to use the new kotlinx-support-jdk8 library to implement a stupid method looking like this:
Copy code
fun 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
Copy code
@Suppress("UNCHECKED_CAST")
    fun search(name: String): List<Exercise> {
        return allExercises.stream()
                           .filter { it.title.contains(name, ignoreCase = true) }
                           .collect(toList()) as List<Exercise>
    }