Prefer Empty Collection (ARCH8088)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key kotlin.performance.prefer-empty-collection · Severity info · Category performance
Flags arrayOf() and the mutable builders (mutableListOf, hashMapOf …) created empty as a return or default - emptyList() / emptySet() / emptyMap() are shared, allocation-free instances. listOf() is NOT reported: the stdlib declares it as emptyList().
Incorrect
Section titled “Incorrect”fun tags(): List<String> = listOf()Correct
Section titled “Correct”fun tags(): List<String> = emptyList()Return emptyList() / emptySet() / emptyMap().