【发布时间】:2019-01-22 09:18:25
【问题描述】:
我想用 Kotlin 写类似的东西。
open class View<P> where P:Presenter<out _this_class_> {
val presenter: P = ...
}
open class Presenter<V> where V: View<out _this_class_> {
val view: V = ...
}
我怎样才能正确地做到这一点?
【问题讨论】:
我想用 Kotlin 写类似的东西。
open class View<P> where P:Presenter<out _this_class_> {
val presenter: P = ...
}
open class Presenter<V> where V: View<out _this_class_> {
val view: V = ...
}
我怎样才能正确地做到这一点?
【问题讨论】:
标准方式(称为F-bounded polymorphism)是
open class View<V: View<V, P>, P: Presenter<out V>> { ... }
根据具体情况,将out 放在此处可能更有意义:
open class View<out V: View<V, P>, out P: Presenter<V>> { ... }
【讨论】: