目录

Kotlin真的会取代JAVA吗

Kotlin真的会取代JAVA吗?

[先来晒一晒Kotlin的几大特点:

Kotlin是静态类型编程语言,用于现代多平台应用,100%可与Java™和Android™互操作 [java] view plain copy]( )

[data class Customer(val name: String, val email: String, val company: String)

Or filter a list using a lambda expression:]( )

[val positiveNumbers = list.filter { it > 0 }

Want a singleton? Create an object:]( )

[object ThisIsASingleton {

val companyName: String = “JetBrains”

}]( )

[var output: String

output = null // Compilation error

Kotlin protects you from mistakenly operating on nullable types]( )

[val name: String? = null // Nullable type

println(name.length()) // Compilation error

And if you check a type is right, the compiler will auto-cast it for you]( )

[fun calculateTotal(obj: Any) {

if (obj is Invoice)

obj.calculateTotal()

}]( )

[import io.reactivex.Flowable

import io.reactivex.schedulers.Schedulers]( )

[Flowable

.fromCallable {

Thread.sleep(1000) // imitate expensive computation

“Done”

}

.subscribeOn(Schedulers.io())

.observeOn(Schedulers.single())

.subscribe(::println, Throwable::printStackTrace)

Target either the JVM or JavaScript. Write code in Kotlin and decide where you want to deploy to]( )

[fun onLoad() {

window.document.body!!.innerHTML += "

Hello, Kotlin!"

}]( )