KtKotlin · Lesson 3 of 8
Functions, when & Expressions
In Kotlin, if and when produce values. Combined with expression-body functions, half your code becomes single readable lines.
✦ Tip
when replaces chains of if/else and Java's switch — no fallthrough, and when used as an expression the compiler forces you to cover every case. Reach for it whenever you branch on one value.
when replaces chains of if/else and Java's switch — no fallthrough, and when used as an expression the compiler forces you to cover every case. Reach for it whenever you branch on one value.