Inspectopedia Help

If-Null return/break/... foldable to '?:'

Reports an if expression that checks variable being null or not right after initializing it that can be converted into an elvis operator in the initializer.

Example:

fun test(foo: Int?, bar: Int): Int { var i = foo if (i == null) { return bar } return i }

The quick-fix converts the if expression with an initializer into an elvis expression:

fun test(foo: Int?, bar: Int): Int { var i = foo ?: return bar return i }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023