Reputation: 957
I am trying to make a copy of a list of objects.The problem I am having is that when I change items in the new copy, the old list gets changed as well. I understand this happens because I add object references to the list. I need to clone objects in new list. But when I try to do it, copy function is not recognized. Here is my code:
val newList = oldList.map { it.copy() }
for copy it says unresolved reference. Any other way to do this?
Upvotes: 2
Views: 1235
Reputation: 36
If your object class is just class ObjectName
, try to replace with data class ObjectName
Upvotes: 2