Kotlin: eliminate nulls from a List (or other functional transformation)
问题 Problem What is the idiomatic way of working around this limitation of the null-safety in the Kotlin type system? val strs1:List<String?> = listOf("hello", null, "world") // ERROR: Type Inference Failed: Expected Type Mismatch: // required: List<String> // round: List<String?> val strs2:List<String> = strs1.filter { it != null } This question is not just about eliminating nulls, but also to make the type system recognize that the nulls are removed from the collection by the transformation. I