Why is a method of superinterface called through Interface.super?

Coder-Man :

When you extend a class in Java you can refer to base class' members through the super reference. However when you have a class A, that implements and interface B, you can only refer to B's methods in this way B.super.method(). Why does the super keyword in the second case have to be prefixed with B.?

Example:

interface Runner {
    default void run() {
        System.out.println("default Runner::run");
    }
}

static class RunnerImpl implements Runner {
    public void run() {
        Runner.super.run(); // doesn't work without "Runner."
    }
}
shmosel :

Because interfaces allow multiple inheritance, which can result in ambiguity for identical methods:

interface Runner1 {
    default void run() {
        System.out.println("default Runner1::run");
    }
}

interface Runner2 {
    default void run() {
        System.out.println("default Runner2::run");
    }
}

static class RunnerImpl implements Runner1, Runner2 {
    public void run() {
        super.run(); // which one???
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=72098&siteId=1