Recursive type parameters in kotlin

后端 未结 1 1901
情歌与酒
情歌与酒 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, P: Presenter> { ... }
    

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

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

    0 讨论(0)
提交回复
热议问题