Details
-
Bug
-
Resolution: Fixed
-
P4
-
7
-
b98
-
generic
-
generic
Description
The following program fails to compile, because the algorithm that identifies a most specific method may require, depending on the order in which methods are considered, that for each pair of methods, one is return-type-substitutable for the other. This is more strict than the guarantee made by the inheritance rules, which is that there exists at least one method among all those that are override-equivalent that is return-type-substitutable for all the others (JLS 8.4.8.4, 9.4.1).
public class ReturnTypeSubstitutable {
interface A { java.io.Serializable m(); }
interface B { Cloneable m(); }
interface C { Object[] m(); }
interface D extends A, B, C {}
interface E extends C, A, B {}
abstract class F implements A, B, C {}
abstract class G implements C, A, B {}
void test(D d, E e, F f, G g) {
d.m(); // error
e.m(); // no error
f.m(); // error
g.m(); // no error
}
}
public class ReturnTypeSubstitutable {
interface A { java.io.Serializable m(); }
interface B { Cloneable m(); }
interface C { Object[] m(); }
interface D extends A, B, C {}
interface E extends C, A, B {}
abstract class F implements A, B, C {}
abstract class G implements C, A, B {}
void test(D d, E e, F f, G g) {
d.m(); // error
e.m(); // no error
f.m(); // error
g.m(); // no error
}
}
Attachments
Issue Links
- relates to
-
JDK-6748088 Abstract classes and interfaces should inherit override-equivalent methods similarly
- Closed
-
JDK-7028808 Incorrect ambiguity error for methods unified by generics
- Resolved