tarek
10/02/2017, 8:44 AMdata class
that inherits from a sealed class
and shares properties with it.
sealed class Base(val id: String) {
data class Child(id: String, val other: String) : Base(id)
data class OtherChild(id: String, val another: Int) : Base(id)
}
But this doesn’t work with data classes as it must only have properties in constructor
sealed class Base(val baseId: String) {
data class Child(val id: String, val other: String) : Base(id)
data class OtherChild(val id: String, val another: Int) : Base(id)
}
This works but the property is duplicated between both classes (and must be named differently in the base class)
sealed class Base(val id: String) {
class Child(id: String, val other: String) : Base(id)
class OtherChild(id: String, val another: Int) : Base(id)
}
This works but I want to have `data class`es
Do you see another solution ?
What am I doing wrong ?