Why demand resolving overriding conflicts when just one implementation is given?

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
    }
}
1 Like

This is so-called diamond problem. A nasty ambiguity that plagues languages with multiple inheritance like C++. Java solution to this problem was to force explicit re-declaration when inheriting two interfaces with default methods. The general reasoning is that when you override default implementation, you are not actually overriding it, but instead replace it. Following this logic, interface A in your example is missing implementation. I do not think that this case is frequent enough to cause problems.