使用不相关的返回类型继承方法 [英] Inherit method with unrelated return types

查看:130
本文介绍了使用不相关的返回类型继承方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码片段

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 {
    }
}

当我尝试编译它时,我收到了错误。

When I try to compile it I got error.


Test.java:12: types Test.I2 and Test.I1 are incompatible; both define m(), but with unrelated return types.


如何避免这种情况?

推荐答案

Java - 接口实现中的方法名称冲突你不能这样做。

作为一种解决方法,你可以创建一个适配器类。

As a workaround, you can create an adapter class.

这篇关于使用不相关的返回类型继承方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆