我有以下代码片段
public class Test {
static interface I1 { I1 m(); }
static interface I2 { I2 m(); }
static interface I12 extends I1,I2 { I12 m(); }
public static void main(String [] args) throws Exception {
}
}
当我尝试编译它时出现错误。
Test.java:12: types Test.I2 and Test.I1 are incompatible; both define m(), but with unrelated return types.
如何避免这种情况?
最佳答案
如 Java - Method name collision in interface implementation 中所述你不能这样做。
作为解决方法,您可以创建一个适配器类。
关于java - 具有不相关返回类型的继承方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9704219/