Kotlin真的會取代JAVA嗎?,Kotlin取代JAVA

來源:互聯網
上載者:User

Kotlin真的會取代JAVA嗎?,Kotlin取代JAVA

原文連結

Kotlin真的會取代JAVA嗎?發布時間:2017-05-31 13:36:061019人關注59人蔘與

自從Kotlin 成為 Android 開發一級語言,Kotlin確實以其實用,高效贏得了海外很多公司和開發人員的認可,比如Square的Jake大神一直在推Kotlin。Kotlin在國外至少有將近2年的應用生產環境的實踐(非JetBrains內部實踐應用)。在移動開發中,相比iOS程式員,Android程式員總是很幸運,因為我們有很多優秀好用的工具(Android Studio等),選用Kotlin,則是Google 為開發人員提供高效的開發工具的一貫作風。

先來曬一曬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:

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"
}

[java] view plain copy

Kotlin 很安全

Get rid of those pesky NullPointerExceptions, you know, The Billion Dollar Mistake

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()
}

[java] view plain copy

方便使用 相容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

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

import kotlin.browser.window

fun onLoad() {
window.document.body!!.innerHTML += "
Hello, Kotlin!"
}

幾篇社區的博文協助大家更好的瞭解kotlin-hello Kotlin-用Kotlin寫Android程式-使用Kotlin&Anko,扔掉XML開發Android應用那麼問題來了你是否已經開始使用準備使用Kotlin?你覺得Kotlin與JAVA之間的區別有哪些,優勢or缺點?你覺得Kotlin會取代JAVA嗎?

 

原文連結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.