Reputation: 434
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.
Upvotes: 3
Views: 2296
Reputation: 170735
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 ...
}
Upvotes: 6
Reputation: 434
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.
Upvotes: 0