What Kotlin Does
- Null safety — types distinguish nullable (
String?) from non-null (String) - Data classes — auto-generate equals, hashCode, copy
- Extension functions — add methods to existing classes
- Coroutines — structured concurrency with suspend functions
- Smart casts — compiler narrows types after checks
- Type inference — minimal explicit typing
- Functional — higher-order, lambdas, collections DSL
- Multiplatform — share code across JVM, JS, Native, iOS, Android
- Compose — Jetpack Compose (Android) and Compose Multiplatform (desktop/web/iOS)
- Full Java interop — call Java from Kotlin and vice versa
Architecture
Kotlin compiler targets JVM bytecode by default (also JS, Native via LLVM, WASM). The Kotlin Multiplatform toolchain compiles shared code for multiple targets. Coroutines are implemented as a compiler transform + runtime library — no OS thread per coroutine.
Self-Hosting
Language toolchain.
Key Features
- Null safety in the type system
- Data classes
- Extension functions
- Coroutines (structured concurrency)
- Higher-order functions and lambdas
- Operator overloading
- Sealed classes + when expressions
- Kotlin Multiplatform
- Jetpack Compose (Android UI)
- Compose Multiplatform (desktop + iOS)
- Gradle Kotlin DSL
Comparison
| Language | Target | Null Safety | Coroutines |
|---|---|---|---|
| Kotlin | JVM/JS/Native | Yes | Yes |
| Java | JVM | Optional | Project Loom |
| Scala | JVM | Option type | Yes |
| Swift | Native | Yes | async/await + actors |
| C# | CLR | Nullable ref types | async/await |
| Go | Native | No | Goroutines |
常见问题 FAQ
Q: 和 Java 比? A: Kotlin 是 Java 的改良版:空安全、数据类、lambda、扩展函数、协程、更少样板。大部分 Java 项目可以逐步迁移到 Kotlin,两种语言可以同一项目共存。
Q: Android 必须用 Kotlin 吗? A: 不是必须,但 Google 强力推荐。2019+ 新 API、官方文档、Android KTX 都以 Kotlin 为主。
Q: Compose Multiplatform 成熟吗? A: 2024 年 Desktop 和 Android 已稳定,iOS 逐步稳定,Web 还在完善。可用于生产但要评估自身需求。
来源与致谢 Sources
- Docs: https://kotlinlang.org/docs
- GitHub: https://github.com/JetBrains/kotlin
- License: Apache 2.0