Values & References12 / 15
Up next

Mutating a passed collection

// the list is shared, so this change is visible to the caller
fun addZero(v: MutableList<Int>) {
    v.add(0)
}

fun main() {
    val nums = mutableListOf(1, 2)
    addZero(nums)
    println(nums)
}
What you're solving

the callee shares the same object