I am no expert to Kotlin, but I'd say you can't achieve this in the way you wrote it.
Check out this answer to question Is Kotlin "pass-by-value" or "pass-by-reference"?. In short, the parameters your function retrieves are passed-by-value and, as such, cannot be swapped. They're not your C pointers.
Now, another answer on StackOverflow explains why you don't even need a swap function in Kotlin and how you can implement the swapping behavior:
var a = 1
var b = 2
a = b.also { b = a }
println(a) // print 2
println(b) // print 1
Now if you really want to implement a swap
function, since the JVM world is pass-by-value, you could implement a wrapper to wrap your integers, something like:
// NOTE You have to use "var" not "val".
data class IntWrapper(var value: Int)
fun swap(a: IntWrapper, b: IntWrapper) {
a.value = a.value xor b.value
b.value = b.value xor a.value
a.value = a.value xor b.value
}
Check out working example.