I would make immutable data classes, and use copy:...
# announcements
m
I would make immutable data classes, and use copy:
val newObj = obj1.copy(name = obj2.name, ....)
.
👍 3
q
i see here is no way to make it, without enumeration of all properties?
val newObj = obj1.copy(obj2)
m
You have to enumerate the properties if you only want to copy some of them.
You won't need to copy the object if you want all properties. If the data class immutable that is. In that case, you could just do
val newObj = obj2
.
By the way, the way you do it with
apply
is idiomatic when you have a mutable object.