ScriptsApr 12, 2026·1 min read

Kotlin — Modern Statically Typed Language for JVM and Beyond

Kotlin is a statically typed, general-purpose programming language developed by JetBrains. Runs on the JVM, Android, native, WebAssembly, and JS targets. Officially endorsed by Google as the preferred language for Android development.

SC
Script Depot · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

# Install via SDKMAN
curl -s https://get.sdkman.io | bash
sdk install kotlin

# Or via Homebrew
brew install kotlin

kotlinc -version
kotlin -version

Hello world:

// Main.kt
fun main() {
    val users = listOf(
        User("Alice", 95),
        User("Bob",   87),
        User("Carol", 91),
    )

    val topUser = users.maxByOrNull { it.score }
    println("Top: ${topUser?.name}")

    users
        .sortedByDescending { it.score }
        .forEach { println("${it.name}: ${it.score}") }
}

data class User(val name: String, val score: Int)
kotlinc Main.kt -include-runtime -d main.jar
java -jar main.jar

Gradle (most common):

// build.gradle.kts
plugins {
    kotlin("jvm") version "2.0.0"
    application
}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
}

application {
    mainClass.set("MainKt")
}
Intro

Kotlin is a statically typed, general-purpose programming language developed by JetBrains. Kotlin compiles to Java bytecode (JVM), JavaScript, WebAssembly, and native binaries. Officially endorsed by Google as a preferred language for Android development in 2017. Now the #1 language for new Android apps and widely used on the server (Spring Boot + Kotlin, Ktor) and multiplatform (Kotlin Multiplatform).

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets