fun MutableList<Int>.swap(index1: Int, index2: Int) {val tmp = this[index1] // 'this' corresponds to the listthis[index1] = this[index2]this[index2] = tmp} fun main(args: Array<String>) { val l = mutableListOf(1, 2, 3,9,60,54,8,21) l.forEachIn
委托模式(Delegation) 类的委托 interface Base { fun print() } class BaseImpl(val x: Int) : Base { override fun print() { print(x) } } class Derived(b: Base) : Base by b fun main(args: Array<String>) { val b = BaseImpl(10) Derived(b).print() // prints 10 } 这里
Kotlin Koans 心印 Introduction 1.Hello, world! Simple Functions Take a look at function syntax and make the function start return the string "OK". In the tasks the function TODO() is used that throws an exception. Your job during the koans will be
Kotlin for Java Developers 学习笔记 ★ Coursera 课程 Kotlin for Java Developers(由 JetBrains 提供)的学习笔记 " From Java to Kotlin Java 和 Kotlin 代码可以相互转化 public class Person { private final String name; private final int age; public Person(String name,
Scala's object-oriented collections support mutable and immutable type hierarchies. Also support functional higher-order operations such as map, filter, and reduce that let you use expression-oriented programming in collections. Higher-order operatio