Function parameters in Kotlin are basically read-only val
's inside the function, so z
here will always refer to the original object that was passed in.
If you need to modify what it points to while your function is running, you'll have to make a local copy of it at the beginning of the function, and then you can make that a var
.
For example, you could start your function like this, which lets you reassign this local var
later:
fun insertFixup(_z: Node?) {
var z = _z
// ...
z = z.parent
// ...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…