Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

504
Visualizações
How to solve 2nd level inheritance with generic classes?

I'm implementing an MVP architecture in Kotlin and Android Studio shows no error, however it doesn't compile:

java.lang.AssertionError: resultingDescriptor shouldn't be null: candidateDescriptor: constructor BasePresenter(view: View) defined in com.exmaple.base.BasePresenter substitution: org.jetbrains.kotlin.types.IndexedParametersSubstitution@70144d7e at org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl.setResultingSubstitutor(ResolvedCallImpl.java:205) ....

Is it possible to use the ConcreteView / ConcretePresenter in the middle of inheritance?

code:

/**
 * These are the base classes
 */
interface MvpView

interface BaseView<Presenter : BasePresenter<*>> : MvpView, HasMvpView<MvpView>

// to avoid circular dependency
interface HasMvpView<View : MvpView> 

abstract class BaseMvpActivity<Presenter : BasePresenter<*>> : AppCompatActivity(), HasMvpView<MvpView>

abstract class BaseMvpFragment<Activity : BaseMvpActivity<*>, Presenter : BasePresenter<*>>: Fragment(), HasMvpView<MvpView> {
        // this will cause the error
        abstract var presenter: Presenter
}


/**
 * There's a Viewpager, and each page looks the same the only difference is their source of data. That's why I tried implementing another level of abstraction over the base classes
 */
interface CategoryPagerView<Presenter: BasePresenter<*>> : BaseView<Presenter>

abstract class CategoryPagerFragment: BaseMvpFragment<LandingActivity, BasePresenter<*>>()

/**
 * A concrete type of the Viewpager's fragment, its presenter and the view
 */
interface ConcreteView : CategoryPagerView<ConcretePresenter> 

class ConcretePresenter(view: ConcreteView) : BasePresenter<*>(view)

class ConcreteFragment : CategoryPagerFragment(), ConcreteView {
        // this line shows no error in the IDE, but in compile time
        override var presenter = ConcretePresenter(this)

Thanks for your help!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's an internal assertion error thrown by the compiler. You can see the compiler source code where this is thrown:

https://github.com/JetBrains/kotlin/blob/master/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallImpl.java

Apparently the resultingDescriptor is null at a point where it should never be null. So it seems like a compiler bug. Maybe it should be rewritten in Kotlin to avoid issues with null :)

Please file a bug report at https://youtrack.jetbrains.com/issues/KT

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda