{ value = "Over 10"; } else { value = "Under 10"; } val a = 10 val value: String if (a > 10) { value = "Over 10" } else { value = "Under 10" } Expression ( if / when / try ) Java Kotlin
{ value = "Over 10"; } else { value = "Under 10"; } val a = 10 val value: String if (a > 10) { value = "Over 10" } else { value = "Under 10" } Expression ( if / when / try ) Java Kotlin
val a = 10 val value = if (a > 10) { "Over 10" } else { "Under 10" } int a = 10; String value; if (a > 10) { value = "Over 10"; } else { value = "Under 10"; }
val value: String if (a === 1) { value = "one" } else if (a === 2) { value = "two" } else if (a === 3) { value = "three" } else { value = "another" } String value; if (a == 1) { value = "one"; } else if (a == 2) { value = "two"; } else if (a == 3) { value = "three"; } else { value = "another"; }
val value: String when { a === 1 -> value = "one" a === 2 -> value = "two" a === 3 -> value = "three" else -> value = "another" } String value; if (a == 1) { value = "one"; } else if (a == 2) { value = "two"; } else if (a == 3) { value = "three"; } else { value = "another"; }
val value = when(a) { 1 -> "one" 2 -> "two" 3 -> "three" else -> "another" } String value; if (a == 1) { value = "one"; } else if (a == 2) { value = "two"; } else if (a == 3) { value = "three"; } else { value = "another"; }
-> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") } Expression ( if / when / try ) Kotlin
-> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") } Expression ( if / when / try ) Kotlin Expression
-> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") } Expression ( if / when / try ) Kotlin Range
-> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") } Expression ( if / when / try ) Kotlin Not In Range
-> print("x is in the range") in validNumbers -> print("x is valid") !in 10..20 -> print("x is outside the range") else -> print("none of the above") } Expression ( if / when / try ) Kotlin Optional, statement / expression
functions • copy() // Destructuring Declarations val jane = User("Jane", 35) val (name, age) = jane println("$name, $age years of age") // prints "Jane, 35 years of age"
= 10 // Int val l = 10L // Long val f = 10F // Float val d = 10.0 // Double val b = true // Boolean val sb = StringBuilder() // StringBuilder val s = "Value" Type Inference
1 money = 1 phone = "123-1234-1234" // More } ൞ݎಞ 5. Code Scope apply Calls the specified function [block] with `this` value as its receiver and returns `this` value.
is here to stay (https://medium.com/peachstudio/get- started-with-kotlin-it-is-here-to-stay-1eaac85ae6a0) • Kotlin: A New Hope in a Java 6 Wasteland (https://academy.realm.io/posts/ droidcon-michael-pardo-kotlin/) • Kotlin ࡄҗ Ӓܿ (http://tech.lezhin.com/2017/08/03/the-case-against-kotlin)