Skip to content

Commit c2d7e63

Browse files
li2weiyi.li
authored andcommitted
Fixed swap list unsupportedOperationException caused by unmodifiable list.
1 parent 7dfb0a6 commit c2d7e63

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

common/src/main/java/me/li2/android/common/collections/CollectionsExt.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fun List<String>.containsIgnoreCase(element: String) =
3030
*/
3131
fun <T> List<T>.swap(indexA: Int, indexB: Int): List<T> {
3232
if (indexA >= size || indexB >= size) return this
33-
Collections.swap(this, indexA, indexB)
34-
return this
33+
val mutableList = this.toMutableList()
34+
Collections.swap(mutableList, indexA, indexB)
35+
return mutableList.toList()
3536
}

0 commit comments

Comments
 (0)