Suppose I have a class Message and a class Channel<T : Message>.
Now, how come I can't cast Channel<out Message> to Channel<Message> without an Unchecked Cast warning?
Shouldn't this cast always be safe since Channel<out Message can only contain objects of type Message or subclasses of type Message?
No, and here is proof.
The only consistent thing to do is to not allow the conversion of
Channel<out Message>toChannel<Message>in this scenario.If it were defined as
Channel<out T: Message>, then this would be safe, but trying to definesendwould cause an error.