Why isn't my generic working properly ?
I created a method that takes a T which implements IGameEvent, then create an EventExecution<T> object that should be of the same type, so if my IGameEvent is of type PlayCardEvent, I expect to get an EventExecution<PlayCardEvent> in return, but I'm just getting an EventExecution<IGameEvent> object, why is that ?
3 Replies
do you have an example of how you're calling this method including the definition of whatever you're passing in?
oh yeah nevermind, that's where the chain breaks
well, shit
yeah, generics are compile time and will infer the type from the type of the argument, not the actual type of the object at runtime
you can work around it with reflection