Data classes in Kotlin are great for eliminating much of the boilerplate of a Java pojo; but when a data class mirrors an interface, the two declarations still appear redundant. Take this example.
interface MyInterface {
val foo: String
val bar: String
val baz: String
val qux: String
}
data class MyImplementation(
override val foo: String,
override val bar: String,
override val baz: String,
override val qux: String
) : MyInterface
Is there any shorthand to eliminate this code duplication, i.e. to tell Kotlin that each val in the interface should be implemented by an identical val in the data class?
All properties in interfaces are abstract by default, so they have to be implemented (declared) by inheritors. According to this links, this feature was not planned in 2015, and it looks like it's still not implemented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With