Back to Intellij Community

SuspiciousCollectionReassignment

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/SuspiciousCollectionReassignment.html

2025.3-rc-2549 B
Original Source

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.

Example:

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
  }