Kotlin中的递归类型参数 [英] Recursive type parameters in kotlin

查看:54
本文介绍了Kotlin中的递归类型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Kotlin中写类似的东西.

I want to write something like that in 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 = ...
}

我该如何正确地做到这一点?

How I can properly do that?

推荐答案

标准方式(称为根据具体情况,将out放在其他位置可能更有意义:

It may make more sense to put out elsewhere here, depending on the specifics:

open class View<out V: View<V, P>, out P: Presenter<V>> { ... }

这篇关于Kotlin中的递归类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆