Community
Participate
Working Groups
I20051220-0800 From the news: -------------------------------------------------- Subject: Multiple inheritance and covariance subtyping in Java 1.5 and jdt core IC.java: interface IA { IA op(); } interface IB { IB op(); } public interface IC extends IA, IB { IC op(); } These classes compile with eclipse and compiler compliance level 5.0 but don't compile with my sun jdk 1.5.0: > javac -version IC.java javac 1.5.0 IC.java:9: types IB and IA are incompatible; both define op(), but with unrelated return types public interface IC extends IA, IB { ^ 1error ----------------------------------------------- The existence of IC#op() seems to suppress the return type substitutability check. As per JLS3 8.4.8.4, "A compile-time error occurs if, for any two such inherited methods, one of the methods is not return type substitutable for the other".
Actually, the reference to JLS3 8.4.8.4 does not apply here (it's for classes). Rather, 9.4.1 should be consulted: "An interface inherits from its direct superinterfaces all methods of the superinterfaces that are not overridden by a declaration in the interface. It is possible for an interface to inherit several methods with override-equivalent signatures (ยง8.4.2). Such a situation does not in itself cause a compile-time error. The interface is considered to inherit all the methods. However, one of the inherited methods must must be return type substitutable for any other inherited method; otherwise, a compile-time error occurs" In this example, "IC op()" in interface IC overrides both of the other methods, so IC does not inherit any op() method! Therefore, the Eclipse compiler is correct in allowing this (with the fix for 122881 comment 3), but jdk1.5.0_06 is wrong. Marking as dup of bug 122881. *** This bug has been marked as a duplicate of 122881 ***