I have data class. For example:
data class Test(
val data: String,
val data2: String
)
Suppose I have a need to change one of the parameters of my data class. For this I will write the following code:
var test = Test(data = "data", data2 = "data2")
test = test.copy(data = "new_data")
But at the same time, I can make a parameter var
and change it directly:
data class Test(
var data: String,
val data2: String
)
var test = Test(data = "data", data2 = "data2")
test.data = "new_data"
Which method is better to use? Suppose that my data class can have a large number of parameters, will there be any problems in this case when using copy()
.
Please, help me.