Back to Intellij Community

WhenWithOnlyElse

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/WhenWithOnlyElse.html

2025.3-rc-2325 B
Original Source

Reports when expressions with only an else branch that can be simplified.

Simplify expression quick-fix can be used to amend the code automatically.

Example:

fun redundant() {
      val x = when { // <== redundant, the quick-fix simplifies the when expression to "val x = 1"
          else -> 1
      }
  }