Kotlin 2 · Basics and null safety

Define functions

Parameters can have defaults and be passed by name. Single-expression functions drop the braces.

fun greet(name: String, greeting: String = "Hello") = "$greeting, $name!"

greet("Ada", greeting = "Hi")

Official Kotlin 2 documentation

More basics and null safety commands

All basics and null safety commands · Kotlin 2 cheatsheet

Was this page helpful?