I\'m implementing a stack algorithm for study purpose in Kotlin
class Stack>(list:MutableList) {
var items: Mutabl
You can fix this by calling toMutableList() api rather than using smart cast (as).
Try: var initialValue = listOf< Int >(10).toMutableList()
Below is a working example:
fun main(){
val x : List = listOf("foo", "bar", "baz")
//val y: MutableList = x as MutableList throws UnsupportedOperationException
val y: MutableList = x.toMutableList()
y.add("sha")
println(y) // [foo, bar, baz, sha]
}