I am having a data class which is having data in form of Lists (Companion Objects). I assign these lists to my variables (lists) in Activity class according to my requirement. The problem is that when I change some list (that was assigned the companion object list value) in Activity class then Companion object list is also changed. Why is this happening? Are Companion objects as assigned by reference? How to avoid this? I want if the variable list of Activity class is changed then companion object list should retain its value.
My code Data List
class DataLists {
companion object {
val CountryList: List<CountryDataStructure> = listOf(
CountryDataStructure(1, "USA"),
CountryDataStructure(2, "Canada"))
}
}
Activity Class
var CountryData = DataLists.CountryList
CountryData[0].Name = "United States of America"
//Here the Companion object list (CountryList) i.e. DataList is also changed and have
//values "United States of America" and "Canada" while I expect this to have "USA" and "Canada"