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

203
Visualizações
Kotlin: Implement generic Interface multiple times with different Subclasses (Base Class is Constraint)

Error Msg: Type parameter E of 'SchedulableInserter' has inconsistent values: Incident, Assignment

So basically I have an abstract class Schedulable. Also I have two classes Incident (Single occuring event, like a timestamp) and a class Assignment(Basically an Incident but with a duration too) I have a MainActivity, where I want to insert Instances into a SQLiteDB. I want to have a different insert-method for every subclass of Schedulable to easily handle the differences between them.

//SchedulableInserter.kt

interface SchedulableInserter<E> where E : Schedulable{
        fun onInsertSchedulable(item:E)
}

//MainActivity.kt

class MainActivity() : AppCompatActivity(),
    NavigationView.OnNavigationItemSelectedListener,
    SchedulableInserter<Incident>, SchedulableInserter<Assignment> {
 /* ^                                ^
    |                                |
   Sadly Kotlin says:
   Type parameter E of 'SchedulableInserter' has inconsistent values: 
   Incident, Assignment
   A Supertype apperars twice
*/
}

I mean I could differentiate within the method if i bind SchedulerInserter to Schedulable, but I would appreciate not having to do that.

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

0

What I'd suggest is having the inserters as properties in the activity instead of implemented interfaces:

class MainActivity() : AppCompatActivity(),
    NavigationView.OnNavigationItemSelectedListener {
    val incidentInserter = SchedulableInserter<Incident> { ... }
    val assignmentInserter = SchedulableInserter<Assignment> { ... }
}

To make that syntax available you currently need to define SchedulableInserter in Java instead of Kotlin; otherwise you have to write

    val incidentInserter = object : SchedulableInserter<Incident> { 
        override fun ...
    }
over 4 years ago · Santiago Trujillo Relatório

0

Answered by Ben P.

Solution:

I mean I could differentiate within the method if i bind SchedulerInserter to Schedulable, but I would appreciate not having to do that.

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