Marcus Brito
11/19/2021, 1:59 PMReceiveBuilder#onMessage
signature.private class MyBehavior<T> : AbstractBehavior<Message<T>>
onMessage(type: Class<T>, handler: Function<T, Behavior<T>>)
type
is supposed to be a subtype of T
, but with the generics argument in there I can’t get it to compile without an explicit castEmil Kantis
11/19/2021, 2:04 PMfun <T, Y: Class<T>> onMessage(type: Y, handler: Function<T, Behavior<T>>)
Marcus Brito
11/19/2021, 2:04 PM::class
will always get the star projection, not the generic variant I need..onMessage(SubType.class, this::handler),
where handler is private Behavior<...> handler(SubType<T> msg)
inline fun <T, reified U : T> ReceiveBuilder<T>.onMessage(noinline handler: (U) -> Behavior<T>): ReceiveBuilder<T> {
return onMessage(U::class.java, handler)
}
return newReceiveBuilder()
.onMessage<MessageProcessorDriverMessage<T>, MessageProcessorDriverMessageReceived<T>> { onMessage(it) }
inline fun <T, reified U : T> ReceiveBuilder<T>.addHandler(noinline handler: (U) -> Behavior<T>): ReceiveBuilder<T> {
return onMessage(U::class.java, handler)
}
return new ReceiveBuilder().addHandler(::onMessage)
Emil Kantis
11/19/2021, 9:30 PM