Skip to Main Content

Inheritance for default and abstract methods from generic interface

3049833Oct 14 2015 — edited Oct 14 2015

According to https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.4.1.3 (Inheriting Methods with Override-Equivalent Signatures)

If an interface I inherits a default method whose signature is override-equivalent with another method inherited by I, then a compile-time error occurs. (This is the case whether the other method is abstract or default.)

The following code compiles (javac 1.8.0_60) without errors. Is this a correct behaviour?

interface A {
    void foo(String x);
}

interface B<T> extends A {
    default void foo(T x) {}
}

interface I extends A, B<String> { } // No errors.
Comments
Post Details
Added on Oct 14 2015
1 comment
409 views