Inspectopedia Help

'when' that can be simplified by introducing an argument

Reports a when expression that can be simplified by introducing a subject argument.

Example:

fun test(obj: Any): String { return when { obj is String -> "string" obj is Int -> "int" else -> "unknown" } }

The quick fix introduces a subject argument:

fun test(obj: Any): String { return when (obj) { is String -> "string" is Int -> "int" else -> "unknown" } }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023