0

code in java:

public interface MvpPresenter<V extends MvpView> {
  public void attachView(V view);
  public void detachView(boolean retainInstance);
}

when I write in kotlin:

interface MvpPresenter<out MvpView> {
    fun attachView(view: MvpView)
    fun detachView(retainInstance: Boolean)
}

fun attachView(view: V) compile error!
So How can I deal with ? extend T in kotlin???

user3163839
  • 31
  • 1
  • 5

1 Answers1

0

You use <V: MvpView>!

Also change the declaration of attachView to:

fun attachView(view: V)

That's defining an upper bound for the generic type V.

So How can I deal with ? extend T in kotlin???

That seems to be somewhat unrelated because you are now talking about generic wildcards. In kotlin, <? extends MvpView> would be <out MvpView>

Sweeper
  • 213,210
  • 22
  • 193
  • 313