Kotlin
Kotlin is JetBrains' concise, null-safe language for Android, backend, multiplatform, and serverless workloads.
Keywords
- as, as?, break, class, companion, const, constructor, continue, crossinline
- data, do, else, enum, expect, external
- false, final, finally, for, fun
- if, import, in, infix, init, inline, inner, interface, internal, is
- lateinit, noinline, null, object, open, operator, out, override
- package, private, protected, public
- reified, return, sealed, super, suspend
- this, throw, true, try, typealias, typeof
- val, var, vararg, when, where, while
Language Features
- Null safety via nullable types (`String?`) and Elvis operator `?:`.
- Extension functions/properties add APIs without inheritance.
- Coroutines deliver structured concurrency with `suspend` functions and flows.
- Data classes auto-generate equals/hashCode/toString/copy.
- Sealed classes and `when` expressions model state machines.
- Kotlin Multiplatform shares business logic across JVM, JS, Native.
Standard Library & Ecosystem
- kotlin.collections adds sequence, list, set, map helpers.
- kotlinx.coroutines for flows, actors, channels, structured scopes.
- Android: Jetpack Compose, Ktor client/server, Retrofit, Room.
- Ktor, Spring Boot, Micronaut, and Vert.x support Kotlin-first backends.
Operators & Idioms
- Safe call `?.`, let/apply/run/scope functions, operator overloading (`operator fun plus`).
- Ranges `1..10`, `downTo`, `until`, `step`.
- Destructuring declarations `(val (name, age) = person)`.
- Smart casts automatically narrow types after checks.
Best Practices
- Enable explicit API mode for libraries.
- Favor immutable `val` over `var`.
- Keep coroutine scopes tied to lifecycles (ViewModelScope, lifecycleScope).
- Use `sealed interface` plus `when` with exhaustiveness checks.
- Adopt detekt/kotlinter and run `./gradlew ktlintCheck` in CI.