Values & References15 / 15
Up next

Read-only view

fun main() {
    val mutable = mutableListOf(1, 2, 3)
    // a read-only view of the same underlying data
    val view: List<Int> = mutable
    mutable.add(4)
    // the view reflects the change but cannot cause one
    println(view)
}
What you're solving

a List view over a MutableList