It is dammage that listOf is not directly implemented with a linkedList, or something else but an implementation which can do smart copy.
Yes I can write this :
val myList2 = LinkedList(myList)
But myList2 is mutable. and How the creation is done to create this LinkedList ? I guess that all elements are copied.
I guess I will look to vavr or guava.
I don’t really understand why kotlin have a feature of immutable list of set with expensive copy.
And about the coply of objects with the copy() methods, how does that happens ?
For example, I have this class :
data class Person(val name: String, val age : Int, val pets : List<Pet> = listOf())
val me = Person("jerem", 32, listOf(halyna, chalie)
val meOlder = me.copy(age = 33)
What happens in this case, does ‘meOlder’ reference the same list of pets than ‘me’ or the list of pet is duplicated ?