I've got following classes.
interface ICommand {. . .}
class ShutdownCommand : ICommand { . . .}
class Message<T> where T : ICommand { . . .}
class Communicator
{
void Send(Message<ICommand> a_msg) { . . .}
}
When I call following code, I get an error that there's no possible conversion from the type Message<ShutdownCommand>
to the Message<ICommand>
. It's not intuitive for me since ShutdownCommand
inherits from ICommand
.
var message = new Message<ShutdownCommand>();
m_communicator.SendCommand(message);
I know I can solve such problem with adding non-generic interface for a Message class and use it as parameter type in Send() method.
Regardless it could be fixed in the way I described above... I'm curious why there's no possible conversion if from the code above arises conversion should be possible.