I’m using nested interfaces in my current project and my interface C inherits from A, B. Both A and B require a fun bar(). Just one of them has an implementation given - still interface C demands a to overwrite fun bar(). Why is that the case?
In the docs i just found that this is how it works, but no statement on why this is needed. What is the reasoning behind that decision?
Below is the (adjusted) quotation of the Resolving overriding conflicts section from the docs.
interface A {
fun foo() { print("A") }
fun bar()
}
interface B {
fun foo() { print("B") }
fun bar() { print("bar") }
}
class C : A, B {
override fun foo() { print("bar") }
override fun bar() {
TODO("Why is this necessary")
}
}
Edit: Just noticed that there is no need to name the specific supertype for .bar
, so the compiler knows that there is just one implementation:
class C : A, B {
override fun foo() {
super<A>.foo() // Needed, as there are multiple implementations
}
override fun bar() {
super.bar() // No explicit supertype qualification needed
}
}