JetBrains • Statically-typed language • JVM Based, compiles to Java bytecode, Javascript, or machine code (Native) • Object-oriented language, support functional programming • Simple, lightweight, interoperate • Is open source
Artist? = null artist?.print() if (artist != null) { artist.print() } var artist: Artist? = null artist!!.print() Kotlin Won’t compile Will do nothing Smart cast Will crash var artist: Artist = null artist.print() Won’t compile
1") 2 -> print("x == 2") else -> { print("x is neither 1 nor 2") } } when { x.isOdd() -> print("x is odd") x.isEven() -> print("x is even") else -> print("x is funny") } value = when { x.isOdd() -> "x is odd" x.isEven() -> "x is even" else -> “x is funny" }
for (i in 6 downTo 0 step 2) { println(i) } for (i in array.indices) { println(array[i]) } for ((index, value) in array.withIndex()) { println("the element at $index is $value") }
architecture, clean code • Easy to maintain, following requirements changed faster • Make product stable, less errors, good performance • Cover by unit test • …
View) { val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) } fun View.showKeyboard() { context.showKeyboard(this) } fun Context.showKeyboard(view: View) { val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager inputMethodManager.showSoftInputFromInputMethod(view.windowToken, 0) }