Question from the Kotlin test

How to add a new element to a list of Kotlin data class

Hard

Considering :

open class Animal
data class Cat(val name : String = "Kitty") : Animal()

The following code :

val cats: MutableList<Cat> = mutableListOf(Cat("Isidor"), Cat("Garfield"), Cat("Rogue"))
val animals: List<Animal> = cats
cats.add(Cat())
animals.forEach({ print(it) })
Author: W3D TeamStatus: PublishedQuestion passed 542 times
Edit
2
Community EvaluationsNo one has reviewed this question yet, be the first!