2017-08-22 300 views
1

我试图将java项目移植到kotlin,并且遇到了一些问题。我有使用泛型Kotlin中的泛型扩展

interface View<P extends Presenter> {} 
interface Presenter<V extends View> {} 
interface BaseView<P extends Presenter> extends View<P> {} 

class BaseActivity<P extends Presenter> extends AppCompatActivity implements BaseView<P> {} 

起初两类我有错误的IDE一些Java中的MVP结构

interface Presenter<V : View<*>> {} 
interface View<P : Presenter<*>> {} 

我的错误是

*this type parameter violates the finite bound restriction* 

没有使用Java代码的任何问题

回答

6

我想这是不允许在Kotlin。

Kotlin spec

下面对声明的是无效的,因为有边缘 Ť→S和S→T,形成一个循环:

interface B<T : C<*>>

interface C<S : B<*>>

原因如下:

在完全展开的形式中,这个界限是无限的。这条规则的目的是 是为了避免这种无限的类型,以及类型检查 与他们有关的困难。

在你的情况下,它是V - > P和P - > V形成一个循环。