0xf1f1
05/11/2025, 3:06 PMsealed interface/sealed class
and using copy()
, how does one create common functions that are shared by all the inheriting data classes without repeating the code ? See changeFooVal()
below. The function performs the exact same operation for all data classes which makes it repetitive + more lines/maintenance overhead.
sealed interface Foo {
val fooVal: String
data class FooX(val fooVal: String) {
fun changeFooVal(value: String): FooX = copy(fooVal = value)
}
data class FooY(val fooVal: String) {
fun changeFooVal(value: String): FooY = copy(fooVal = value)
}
}
Chrimaeon
05/11/2025, 4:22 PM