https://kotlinlang.org logo
#announcements
Title
# announcements
m

marstran

10/06/2017, 11:45 AM
I would make immutable data classes, and use copy:
val newObj = obj1.copy(name = obj2.name, ....)
.
👍 3
q

qwert_ukg

10/06/2017, 12:38 PM
i see here is no way to make it, without enumeration of all properties?
val newObj = obj1.copy(obj2)
m

marstran

10/06/2017, 12:47 PM
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.