KT.DONT_DOWNCAST_COLLECTION_TYPES
Down-casting immutable collection types
Down-casting immutable types from kotlin.collections should be discouraged. The result of the downcast is platform specific and can lead to unexpected crashes. Prefer to use instead the toMutable<Type>() functions.
Noncompliant Code
Copy
val list: List<Int> = getAList()
if (list is MutableList) {
list.add(42)
}
(list as MutableList).add(42)
Compliant Code
Copy
val list: List<Int> = getAList()
list.toMutableList().add(42)