Untitled

Run Settings
LanguageKotlin
Language Version
Run Command
// 扩展函数 swap,调换不同位置的值 fun MutableList<Int>.swap(index1: Int, index2: Int) { val tmp = this[index1] // this 对应该列表 this[index1] = this[index2] this[index2] = tmp } fun main(args: Array<String>) { val l = mutableListOf(1, 2, 3) // 位置 0 和 2 的值做了互换 l.swap(0, 2) // 'swap()' 函数内的 'this' 将指向 'l' 的值 println(l.toString()) }
Editor Settings
Theme
Key bindings
Full width
Lines