Inspectopedia Help

If-Then foldable to '?:'

Reports if-then expressions that can be folded into elvis (?:) expressions.

Example:

fun maybeFoo(): String? = "foo" var foo = maybeFoo() val bar = if (foo == null) "hello" else foo

The quick fix converts the if-then expression into an elvis (?:) expression:

fun maybeFoo(): String? = "foo" var foo = maybeFoo() val bar = foo ?: "hello"

Inspection options

Option

Type

Default

Report also on statement

Checkbox

false

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023