Recursive type parameters in kotlin

后端 未结 1 1911
情歌与酒
情歌与酒 2021-01-19 22:32

I want to write something like that in Kotlin.

open class View

where P:Presenter { val presenter: P = ... } open class

相关标签:
1条回答
  • 2021-01-19 22:35

    The standard way (called F-bounded polymorphism) is

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

    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>> { ... }
    
    0 讨论(0)
提交回复
热议问题