Skip to content

Files

Latest commit

 

History

History
31 lines (20 loc) · 489 Bytes

UseOrEmpty.md

File metadata and controls

31 lines (20 loc) · 489 Bytes

Pattern: Use of ?: emptyList()

Issue: -

Description

Detects ?: emptyList() that can be replaced with orEmpty() call.

Example of incorrect code:

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

Example of correct code:

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

Further Reading