Arnab
04/07/2026, 10:32 AMinterface EventConsumer<EventType: DomainEvent> {
fun handleEvent(event: EventType)
}
class MyConsumer: EventConsumer<Foo> {
...
}
fun main() {
val consumer = MyConsumer()
val events: List<DomainEvent> = ...
events.forEach {
consumer.handle(it)
}
}
I want to find a way where only the events of type Foo are handled, but the rest are skipped. But I can't do something like this:
interface EventConsumer<EventType: DomainEvent> {
fun isRelevant(eventWithGlobalNr: EventWithGlobalNr<DomainEvent>): Boolean = EventType::class.isInstance(eventWithGlobalNr.event) // Cannot use 'EventType' as reified type parameter. Use a class instead.
}Klitos Kyriacou
04/08/2026, 10:12 AMconsumer.handleEvent(it) would fail to compile because it only takes a Foo type.