is there a reflective way to copy A to B in kotlin...
# announcements
x
is there a reflective way to copy A to B in kotlin (where A and B are different instances of different classes but share the same attributes)
d
You could use java.lang.reflect.* to do that, but I recommend just assigning the attributes manually unless there are a lot of them for some reason.
x
yeah, wasn’t sure if maybe kotlin had something similar to a ReflecionUtils.copyProperties. I probably should just do it by hand.
b
Also doing something like this with reflection can easily break if one property of a class is renamed, leading to very obscure bugs
1
x
yes, I know, I’ve had something like this break before when spring changed its implementation. ah well looks like idea was able to generate a constructor call for me somehow… I only wish it could generate all the setter calls for me.