'if' condition can be replaced with lambda call
Reports isEmpty
, isBlank
, isNotEmpty
, or isNotBlank
calls in an if
statement to assign a default value.
The quick-fix replaces the if
condition with ifEmpty
or ifBlank
calls.
Example:
fun test(list: List<Int>): List<Int> {
return if (list.isEmpty()) {
println()
foo()
} else {
list
}
}
After the quick-fix is applied:
fun test(list: List<Int>): List<Int> {
return list.ifEmpty {
println()
foo()
}
}
This inspection only reports if the Kotlin language version of the project or module is 1.3 or higher.
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Kotlin, @snapshot@ |
Last modified: 13 July 2023