When working with `sealed interface/sealed class` ...
# android
u
When working with
sealed 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)
}
}
c
Better move this question to #C0B8MA7FA