jeff
02/02/2022, 2:00 AMinterface HasName {
val name: String
fun copy(name: String = name) // boilerplate (but only once)
}
data class Person(
override val name: String,
val age: Int
) : HasName {
override fun copy(name: String = name) // boilerplate (in everything that extends HasName)
}
// Because I want to do this:
val named: HasName = Person(...)
named.copy(name = "newName")
Joffrey
02/02/2022, 2:03 AMcopy
anywhere. Is the implementation of that method supposed to be different in different implementations of HasName
? What "boilerplate" are you trying to get rid of exactly?jeff
02/02/2022, 2:05 AMhfhbd
02/02/2022, 9:57 AMfun HasName.copy(...) = with (this) { is Person -> copy(...) }