DEV Community

loading...

Discussion on: How to get rid of switch statements

Collapse
vaclavhodek profile image
vaclavhodek

The switch - case - break is another reason to love Kotlin's when :-).

when(x) {
  0 -> doA()
  1 -> doB()
  2 -> {
    doC()
    doD()
  }
  else -> doE()
}
Enter fullscreen mode Exit fullscreen mode
Forem Open with the Forem app