In Kotlin, suppose I have two dataclasses that hav...
# announcements
n
In Kotlin, suppose I have two dataclasses that have some shared fields. In python dataclasses, I would solve this by factoring the shared fields into another dataclass, and then inheriting from both, and things like equality would work as expected. kotlin doesn't allow inheritance of dataclasses, so how would you solve this problem?
y
Use composition - either have one data class reference the other, or create a third data class that is used by both.
n
@yawkat there's extensive discussion on why that doesn't work. Basically, that causes nesting, whereas I want things ot be flat.
y
well, that's the idiomatic way to do it - what may be a good idea in other languages isn't necessarily a good idea in kotlin/java