Need help in this scenario, Clone a Derived Instan...
# announcements
z
Need help in this scenario, Clone a Derived Instance from a Base Object
Copy code
open class Player(override val playerName: String, override val id: Int) : FantasyPlayer

data class TeamPlayer(
    override val playerName: String,
    override val id: Int,
    val teamId: Int,
    val isCaptain: Boolean = false,
    val isSelected: Boolean = false
) : Player(playerName, id)
So, I have a player object and I want to create instance of another class which is actually extended from the base and I want to copy all the property values to this extended class, is this the correct approach or is it even possible\. For example,
Copy code
val player = Player("Beckham", 1, 1)

val teamPlayer = TeamPlayer(// player, 10, true, true)
n
I think what you need to to is to add a 2nd constructor to
TeamPlayer
: see https://pl.kotl.in/rMtrAGczK
z
Thank you @nkiesel though from oops point of view is this the correct way?
n
Ok for me. Though I would rather use a normal class instead of a data class. See https://pl.kotl.in/93hdgS8Ca
­čĹŹ 1