I am new to Kotlin and I try to understand the shown short code for swapping the values of two variables. I don't understand why it and b have different values in the also function. Don't they reference the same memory address with decimal value 2?
Thank you.
var a = 1
var b = 2
println("a=$a b=$b") // a=1 b=2
a = b.also {
b = a
println("it=$it b=$b") // it=2 b=1. Returns it
}
print("a=$a b=$b") // a=2 b=1