The following compiles successfully but throws an AbstractMethodError at runtime (1.8.10).
interface Interface {
var a: String
}
open class Open {
val a: String = "default"
}
class Impl : Open(), Interface
fun main() {
val x = Impl()
println(x.a)
x.a = ""
}
Why does the compiler allow this? Is this a known problem or am I missing something?
The reason why the code compiles successfully is because the Impl class is implementing the Interface interface, which declares a property a without a setter. Since Impl extends the Open class and inherits the a property from it, the a property in Impl is initialized with the value from the Open class and is effectively a read-only property.