AnatomyOf

Anatomy of a Kotlin file

example.kt
1package com.example.minimal
2
3data class Task(val title: String, var done: Boolean)
4
5fun describe(task: Task?): String {
6 // The Elvis operator (?:) has left the building, but never a NullPointerException
7 val name = task?.title ?: "Untitled"
8 return "Task: $name"
9}
10
11fun main() {
12 val tasks = listOf(Task("Write code", false), Task("Ship it", true))
13
14 for (task in tasks) {
15 println(describe(task)) // no semicolons were harmed in the making of this loop
16 }
17}
Kotlin is a modern, concise, statically typed language with first-class JVM and Android support plus JavaScript, WebAssembly, and native compilation targets.