Why Kotlin
Modern, concise and safe programming language
-
简洁
/* 使用一行代码创建一个包含 getters、 setters、 `equals()`、 `hashCode()`、 `toString()` 以及 `copy()` 的 POJO: */ data class Customer(val name: String, val email: String, val company: String) // 或者使用 lambda 表达式来过滤列表: val positiveNumbers = list.filter { it > 0 } // 想要单例?创建一个 object 就可以了: object ThisIsASingleton { val companyName: String = "JetBrains" }
-
安全
/* 彻底告别那些烦人的 NullPointerException——著名的十亿美金的错误 */ var output: String output = null // 编译错误 // Kotlin 可以保护你避免对可空类型进行误操作 val name: String? = null // 可空类型 println(name.length()) // 编译错误 // 并且如果类型检测正确,编译器会为你做自动类型转换 fun calculateTotal(obj: Any) { if (obj is Invoice) obj.calculateTotal() }
-
互操作性
/* 使用 JVM 上的任何现有库,因为有 100% 的兼容性,包括 SAM 支持。 */ import io.reactivex.Flowable import io.reactivex.schedulers.Schedulers Flowable .fromCallable { Thread.sleep(1000) // 模仿高开销的计算 "Done" } .subscribeOn(Schedulers.io()) .observeOn(Schedulers.single()) .subscribe(::println, Throwable::printStackTrace)
// 无论是面向 JVM 还是 JavaScript 平台,都可用 Kotlin 写代码然后部署到你想要的地方 import kotlin.browser.window fun onLoad() { window.document.body!!.innerHTML += "<br/>Hello, Kotlin!" }
Easy to pick up, so you can create powerful applications immediately.
Get started →A productive way to write server‑side applications
Compatible with the Java ecosystem. Use your favorite JVM frameworks and libraries.
Learn more →Natural way to share code between mobile platforms
Write the business logic for iOS and Android apps just once. Easily make existing applications cross platform.
Browse KMM →Big, friendly and helpful community
Kotlin has great support and many contributors in its fast-growing global community. Enjoy the benefits of a rich ecosystem with a wide range of community libraries. Help is never far away – consult extensive community resources or ask the Kotlin team directly.
Join the community →