KT.USE_OR_EMPTY

Call '?: emptyList()' can be replaced with 'orEmpty()'

This rule detects ?: emptyList() that can be replaced with orEmpty() call.

Noncompliant Code

Copy
fun test(x: List<Int>?, s: String?) {
    val a = x ?: emptyList()
    val b = s ?: ""
}

Compliant Code

Copy
fun test(x: List<Int>?, s: String?) {
    val a = x.orEmpty()
    val b = s.orEmpty()
}

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html