Type projection gives a parameterized type a restricted view. An out projection permits reading the type parameter but prevents passing values into it; an in projection permits the opposite direction. This lets functions express the operations they actually need. section 11.3.5
Copying through an out projection
fun <T> copyData(source: MutableList<out T>, destination: MutableList<T>) { for (item in source) destination.add(item) } The source can provide T values, but source.add(...) is rejected. For example, MutableList<out Number> cannot accept 42 because its exact element type is unknown. Use a regular type when the function must call prohibited methods; alternatively, separate the source and destination types with a bound such as <T: R, R>.
Accepting values with an in projection
fun <T> copyData(source: MutableList<T>, destination: MutableList<in T>) { for (item in source) destination.add(item) } The destination is treated as a consumer of T values.
