how do i create a type that hosts a list of items that implement an interface but have different typed parameters?

You don’t. IEngine<int, string> and IEngine<string, int> are, on a type-theoretical level, completely unrelated types and putting them in the same list makes no sense.

If there is a reasonable way that an engine can be used regardless of its parameters, extract that functionality into a parameterless superinterface and make the list typed to that.

If there is no reasonable way to do that, you can’t do polymorphic dispatch anyway, so you need type tests and might as well use a list of Object too.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top