Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda