Hi guys, I'm having trouble understanding the diff...
# getting-started
a
Hi guys, I'm having trouble understanding the difference between these: With abstract class:
Copy code
abstract class ParentObject(val id: Int)
class ChildObject(id: Int, val value: String) : ParentObject(id)
With adt/sealed class it doesn't compile:
Copy code
sealed class ParentObject(val id: Int)
data class ChildObject(id: Int, val value: String) : ParentObject(id)
Is there any way to get it working in Kotlin? I want the benefits of the data classes but there are some fields that are common for all my subtypes.
s
Copy code
sealed class ParentObject {
    abstract val id: Int
}
data class ChildObject(override val id: Int, val value: String) : ParentObject()
👍 1
a
Thank you for your quick reply- I was trying to follow the compiler error and use the "overriding" somewhere 🙂 but I couldn't get it to work.