Java到Kotlin泛型翻译

我想转移到Kotlin旧的Java项目,并发现有趣的,不能没有痛苦地转换这Kotlin

public interface BaseJView<P extends BaseJPresenter> { P createPresenter(); } public interface BaseJPresenter<V extends BaseJView> { void bindView(V view); } 

你能提供意见,我怎么能做到这一点?

一种方法是使用递归类型定义,如下所示:

 interface BaseJView<TSelf : BaseJView<TSelf, P>, P : BaseJPresenter<P, TSelf>> { fun createPresenter(): P } interface BaseJPresenter<TSelf : BaseJPresenter<TSelf, V>, V : BaseJView<V, TSelf>> { fun bindView(view: V) } 

你可以有:

 class Presenter : BaseJPresenter<Presenter, View> { override fun bindView(view: View) { ... } } class View : BaseJView<View, Presenter> { override fun createPresenter(): Presenter { ... } }