Okay, this technically works (and is probably what I’ll end up doing), but now the T
in Msg<T>
isn’t actually the same T
as BroadcastChannel<T>
's T
(meaning I think Msg<T>
is defining a new T
type). However, that actually doesn’t seem to matter, but it’s mildly confusing – the following works just fine:
class BroadcastChannel<T>(context: CoroutineContext = CommonPool) {
private sealed class Msg<Ignored> { // can be generic on...anything
class Subscribe<T>(val channel: SendChannel<T>): Msg<T>()
class Broadcast<T>(val obj: T): Msg<T>()
}
// snip
}
So Subscribe
can continue to have a generic type that matches the outer T
. Cool, good enough for now. Thanks!