juniorKotlin

What is a when expression?

Updated May 16, 2026

Short answer

when is Kotlin’s switch replacement.

Deep explanation

It supports multiple conditions, ranges, and even type checks.

Real-world example

Handling UI states in apps.

Common mistakes

  • Forgetting else branch.

Follow-up questions

  • Can when return values?
  • Can when be used without argument?

More Kotlin interview questions

View all →