Inspectopedia Help

Augmented assignment creates a new collection under the hood

Reports augmented assignment (+=) expressions on a read-only Collection.

Augmented assignment (+=) expression on a read-only Collection temporarily allocates a new collection, which may hurt performance.

Change type to mutable quick-fix can be used to amend the code automatically.


fun test() { var list = listOf(0) list += 42 // A new list is allocated here, equivalent to list = list + 42 }

After the quick-fix is applied:

fun test() { val list = mutableListOf(0) list += 42 }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Kotlin, @snapshot@

Last modified: 13 July 2023