I have a data class:
data class Person (
val login: String,
val password: String
)
Sometimes I need to instantiate it with my custom data, but sometimes I need to initialize my user by another class instance:
val authPerson = api.getAuthPerson() // AuthPerson class has the same fields
val user = User(authPerson)
I wrote secondary constructor, but it doesn't work:
data class User (
val login: String,
val password: String
) {
constructor(authPerson: AuthPerson) {
login = authPerson.login;
password = authPerson.password
}
}
Can anybody advise me correct decision please?