Kotlin Cheat Sheet
|
This section documents Kotlin 2.4.x on the JVM, as published at kotlinlang.org, which is the reference these pages are written and verified against. This content was generated with the assistance of AI and should be verified against kotlinlang.org before being relied on in production. This section’s bibliography lists the reference material consulted while preparing these pages. |
A single-page, colour-coded summary of the Kotlin essentials — types and val/var, string templates, ranges,
control flow as expressions, functions with default/named arguments, classes and data class, inheritance and
delegation, sealed classes and enums, objects and companion objects, extension and scope functions, lambdas and
inline, generics and variance, null safety (?./?:/!!/as?), equality and operator overloading,
collections and sequences, exceptions and Result, coroutines, coroutine context/cancellation, flows, and
Android/tooling one-liners — handy for quick memorization or as a printable desk reference.
For the full explanation, every option, and additional examples, see the dedicated pages:
Getting started — Getting Started and Kotlin and the JVM.
Language fundamentals — Lexical Structure and Style, Basic Types and Variables, Strings and Text, Operators and Ranges, Control Flow, and Functions.
Object-oriented and functional programming — Classes and Objects, Inheritance and Interfaces, Data Classes and Destructuring, Sealed Classes and Enums, Objects and Companion Objects, Extension Functions and Scope Functions, and Lambdas and Higher-Order Functions.
Type system — Generics and Variance, Null Safety, and Equality and Operator Overloading.
Collections and metaprogramming — Collections and Sequences, Annotations and Reflection, and Type-Safe Builders and DSLs.
Error handling — Exceptions and Error Handling.
Coroutines — Coroutines Basics, Coroutine Context, Cancellation and Exceptions, and Flows.
Kotlin on Android and tooling — Kotlin for Android, Build and Tooling, and Testing.