interface A {
val x : Int
}
interface B : A {
override val x: Int
get() = 1
}
open class C(
final override val x: Int
) : A
class D(
x: Int
) : C(x), B // Error : Class 'D' must override public final val x: Int defined in C because it inherits many implementations of it
// but how to override if x is final in C ?
j
Jacob
08/27/2023, 8:54 PM
I don't think you can. This looks like the classic "diamond of death" with the
final
disabling the workaround
c
CLOVIS
08/28/2023, 7:44 AM
Copy code
how to override if x is final in C
You can't.
final
means "forbid overriding", so it's forbidden.
p
PHondogo
08/28/2023, 10:24 AM
I thought Interface DEFAULT implementetion means applying it if there is no class implementation even if class is super.
c
CLOVIS
08/28/2023, 10:25 AM
Yes. D has a super class, so C takes priority.
p
PHondogo
08/28/2023, 10:38 AM
I also thought so. But it is not. I've got compilation error.