1 min readOct 10, 2019
That sentence means that the out
parameters allows List
to be flexible.
In kotlin there are two main type of lists:
- immutable
List<>
- mutable
MutableList<>
List
is covariant and therefore we can do the following:
val integers = listOf<Int>(1)
val number : List<Number> = integers
`MutableList
is invariant (limited) so the following code will result in compile time error
val mutableIntegers = mutableListOf<Int>(1)
val mutableNumber : MutableList<Number> = mutableIntegers // error Type missmatch
Let me know if this helps!