C
C#7mo ago
Althos

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 ?
No description
3 Replies
Jimmacle
Jimmacle7mo ago
do you have an example of how you're calling this method including the definition of whatever you're passing in?
Althos
AlthosOP7mo ago
oh yeah nevermind, that's where the chain breaks well, shit
Jimmacle
Jimmacle7mo ago
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
Want results from more Discord servers?
Add your server