https://kotlinlang.org logo
#language-evolution
Title
# language-evolution
v

vngantk

12/23/2022, 10:11 PM
What do you mean by passing function argument by ref?
p

PHondogo

12/24/2022, 8:14 AM
I mean this:
Copy code
fun test(ref v: Int) {
  ++v
}

var x = 1
test(x)
println(x) // 2
Also for objects:
Copy code
fun test(ref v: Any?) {
  v = Test()
}
var x: Any? = null
test(x)
// x points to created in test object of class Test
May be explicitly specify passing by ref at call site. For example:
Copy code
test(ref x)
2 Views