Indeed, you do not need an abstract class . you can just override interface properties, for example:
interface B { val id: Int? }
An interface has no constructors, so you cannot invoke the constructor using the super(..) keyword, but you can use an abstract class . Howerver, the data class cannot declare any parameters on the primary constructor , so it will overwrite the field superclass, for example:
// v--- makes it can be override with `open` keyword abstract class B(open val id: Int?) // v--- override the super property by `override` keyword data class A(override var id: Int) : B(id) // ^ // the field `id` in the class B is never used by A // pass the parameter `id` to the super constructor // v class NormalClass(id: Int): B(id)
source share