hashCode(), toString() and copy() in a single line: data class Customer(val name: String, val email: String, val company: String) Want a singleton? Create an object: object ThisIsASingleton { val companyName: String = "JetBrains" } Stanfy MadCode #10
Does not compile. val y: String = null // Does not compile. if (x != null) { x.length // Compiles! Not idiomatic just to get length! } // Same as above (IntelliJ auto-suggested the change). x?.length // Elvis operator. val len = x?.length ?: -1 val len = x!!.length // Will throw if null. Rarely used. Stanfy MadCode #10
frameworks 100% Java Interoperability JavaScript compiler to target Node.js environment Very small runtime and stdlib for Android development ~ 1MB Stanfy MadCode #10
val tmp = this[index1] // 'this' corresponds to the list this[index1] = this[index2] this[index2] = tmp } val l = mutableListOf(1, 2, 3) l.swap(0, 2) Stanfy MadCode #10
number: Double) : Expr() class Sum(val e1: Expr, val e2: Expr) : Expr() object NotANumber : Expr() } fun eval(expr: Expr): Double = when(expr) { is Const -> expr.number is Sum -> eval(expr.e1) + eval(expr.e2) NotANumber -> Double.NaN // the `else` clause is not required because we've covered all the cases } Stanfy MadCode #10
"", val age: Int = 0) /* * fun copy(name: String = this.name, age: Int = this.age) = User(name, age) */ val adam = User("Adam", 35) val jane = adam.copy(name = "Jane") val (name, age) = jane println("$name, $age years of age") // prints "Jane, 35 years of age" Stanfy MadCode #10
- https://kotlinlang.org/ Already have a huge community - Slack channel Not as known as Scala or Groovy yet Still in beta - syntax changes, missing features, hidden bugs Using Project Kotlin for Android by Jake Wharton Stanfy MadCode #10
functional yet ◦ Better Annotation Processing: Supporting Stubs in kapt • Mockito sometimes behaves wildly ◦ How to use Mockito with Kotlin? • New testing framework - Spek ◦ http://jetbrains.github.io/spek/ • Extension functions break incremental compilation ◦ All hopes for new beta Stanfy MadCode #10