abstract class BaseEventConsumer<EV : TBase<...
# announcements
s
abstract class BaseEventConsumer<EV : TBase<EV, out TFieldIdEnum>, ID>(val topic: String) we are using kafka, and I don't understand the meaning of EV, EV: TBase<EV, out TFieldEnum> .
s
so to start,
EV
is declared as a generic parameter that is required to be a type that is or inherits from
TBase
and is parameterized with
EV
and a covariantly-specified (i.e. “this type or a subtype”)
TFieldEnum
if this is confusing, you’re not alone lmao
it both involves variance and is a recursively-defined generic
s
I don’t know about kafka programming per se, but this typedef requires that you can create your own implementation of a
BaseEventConsumer
and your own event-type that implements
TBase
and the first type-parameter of
BaseEventConsumer
needs to be such a event-type:
Copy code
class MyFieldIdEnum : TFieldIdEnum { ...}

class MyEvent : TBase<MyEvent, MyFieldIdEnum> { ...  }

class MyConsumer: BaseEventConsumer<MyEvent, String>("topic") { .... }
The recursive type-def of
EV: TBase<EV, ...>
is similar to that of
C: Comparable<C>