This program fails to compile:
interface Sup<X> {
boolean m(X x);
}
interface Sub<X> extends Sup<String> {
boolean m(String s);
}
class Test {
void test() {
Sub s = new Sub() {
@Override
public boolean m(String o) { return true; }
};
}
Compiler says:
Main.java:15: error: <anonymous Test$1> is not abstract and does not override abstract method m(Object) in Sup
Sub s2 = new Sub() {
^
1 error
This seems to be inconsistent with the notion that 'overridden methods should not be inherited'.
Note: this also affect the functional interface check as of JDK 8.
interface Sup<X> {
boolean m(X x);
}
interface Sub<X> extends Sup<String> {
boolean m(String s);
}
class Test {
void test() {
Sub s = new Sub() {
@Override
public boolean m(String o) { return true; }
};
}
Compiler says:
Main.java:15: error: <anonymous Test$1> is not abstract and does not override abstract method m(Object) in Sup
Sub s2 = new Sub() {
^
1 error
This seems to be inconsistent with the notion that 'overridden methods should not be inherited'.
Note: this also affect the functional interface check as of JDK 8.
- relates to
-
JDK-8074381 java.lang.AssertionError during compiling
-
- Closed
-