【发布时间】:2023-02-02 00:51:49
【问题描述】:
我有通用接口...
interface Parent<T> {
fun function(entity: T): Int
}
当我用一些子类实现功能时......
class Other : Parent<Other> {
override fun function(entity: Other): Int {
return 42
}
}
我对在实现接口时必须传递相同的类类型这一事实感到困扰......我真的希望接口能够检测到它自己附加了哪个类,而无需我再次提供相同的类型...
我想要这样的代码......
class Other : Parent {
override fun function(entity: Other): Int {
return 42
}
}
在科特林中是否有可能以某种形式做到这一点?
【问题讨论】:
-
这不可能。