Back to Intellij Community

RedundantElseInIf

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

2025.3-rc-2353 B
Original Source

Reports redundant else in if with return

Example:

fun foo(arg: Boolean): Int {
      if (arg) return 0
      else { // This else is redundant, code in braces could be just shifted left
          someCode()
      }
  }

After the quick-fix is applied:

fun foo(arg: Boolean): Int {
      if (arg) return 0
      someCode()
  }