Daniele B
04/07/2021, 4:45 PMupdate( B(firstField = objA.name, secondField = objB.surname) )
into something similar to this? (it doesn’t work)
update( ::objA )
given that the two classes have the same structure but just different property names?
so that I don’t need to manually specify each field?
val objA = A("John", "Walker")
fun update(obj : B) {
...
}
data class A (
val name : String
val surname : String
)
data class B (
val firstField : String
val secondField : String
)
N.B. I cannot modify the classes definition, by extending or implementing interfacesRoukanken
04/07/2021, 4:51 PMA.toB()
which creates B
from A
, and just use that everywhereupdate(objA.toB())
)Daniele B
04/07/2021, 4:55 PMRoukanken
04/07/2021, 4:56 PMDaniele B
04/07/2021, 5:01 PMephemient
04/07/2021, 5:57 PMDaniele B
04/07/2021, 7:16 PM