I have the following class:
abstract class PresenterActivity<S : ViewState, I : ViewIntent> : AppCompatActivity() {
open fun initViewIntent(): I {
return object : ViewIntent{} // type mismatch on this line
}
}
I receive a pre-compilation error stating:
Type mismatch
Required: I
Found: <S, I>
To fix this pre-compilation error I am casting the ViewIntent object to I:
abstract class PresenterActivity<S : ViewState, I : ViewIntent> : AppCompatActivity() {
open fun initViewIntent(): I {
@Suppress("UNCHECKED_CAST")
return object : ViewIntent{} as I
}
}
But why can't Kotlin detect that I
must be derived from ViewIntent
and smart cast it?