I ran the following code in both kotlinc
and ki
(github)
data class Person(val name: String, val roles: List<String>)
val m = Person("bob", mutableListOf("developer"))
m.roles.addFirst("a")
In kotlinc
, I got an error message:
> kotlinc -script Immutable.kts
Immutable.kts:4:9: error: unresolved reference 'addFirst'.
m.roles.addFirst("a")
^
However, ki
allowed me to modify the mutable list roles
:
> ki
ki-shell 0.5.2/1.7.0
type :h for help
[0] data class Person(val name: String, val roles: List<String>)
[1] val m = Person("bob", mutableListOf("developer"))
[2] m.roles.addFirst("a")
[3] m.roles
res3: List<String> = [a, developer]
So, why the code returns two different outcomes depending on how it was executed?