我想在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 = ...
}
我该怎么做呢?
答案 0 :(得分:4)
标准方式(称为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>> { ... }