Kotlin界面实现“明确”

时间:2019-11-07 12:38:56

标签: kotlin

我有两个具有相同签名方法的接口,但返回类型不同。界面如下图所示,

interface IIntCalculation {
    fun Add(a:Int, b:Int): Int
}

interface IDoubleCalculation {
    fun Add(a:Int, b:Int): Double
}

当我尝试实现这些接口时,显然它将与相同的签名发生冲突,并显示为错误。重载冲突:public open fun Add(a:Int,b:Int):测试中定义的Int。计算,公开开放乐趣Add(a:Int,b:Int):在test.Calculation中定义了double。示例代码如下,

class Calculation : IIntCalculation, IDoubleCalculation {
    override fun Add(a: Int, b: Int): Int {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun Add(a: Int, b: Int): Double {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}

那么,我可以明确实现这些接口吗?

在此先感谢您提供任何帮助和建议。

0 个答案:

没有答案