gpt4 book ai didi

java - 具有不相关返回类型的继承方法

转载 作者:搜寻专家 更新时间:2023-11-01 02:51:52 25 4
gpt4 key购买 nike

我有以下代码片段

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com