Skip to content

Files

Latest commit

 

History

History
31 lines (22 loc) · 546 Bytes

OptionalWhenBraces.md

File metadata and controls

31 lines (22 loc) · 546 Bytes

Pattern: Unnecessary braces in when

Issue: -

Description

These optional when braces should be removed.

Example of incorrect code:

val i = 1
when (i) {
    1 -> { println("one") } // unnecessary curly braces since there is only one statement
    else -> println("else")
}

Example of correct code:

val i = 1
when (i) {
    1 -> println("one")
    else -> println("else")
}

Further Reading