先来晒一晒Kotlin的几大特点:
Kotlin是静态类型编程语言,用于现代多平台应用,100%可与Java™和Android™互操作 [java] view plain copy
Kotlin是非常简介的编程语言
Create a POJO with getters, setters, equals(), hashCode(), toString() and copy() in a single line:
val positiveNumbers = list.filter { it > 0 }
Want a singleton? Create an object:
object ThisIsASingleton {
val companyName: String = "JetBrains"
}
Kotlin 很安全
Get rid of those pesky NullPointerExceptions, you know, The Billion Dollar Mistake
fun calculateTotal(obj: Any) {
if (obj is Invoice)
obj.calculateTotal()
}
方便使用 兼容JVM上现有library
Use any existing library on the JVM, as there’s 100% compatibility, including SAM support.
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
fun onLoad() {
window.document.body!!.innerHTML += "
Hello, Kotlin!"
}