I’ve spent a few hours on and off trying to find an answer to this, I’m probably having trouble with wording the question correctly, which doesn’t help. Essentially, I have an abstract class:
public abstract class GenericType<T>
{ ... }
And a bunch of classes that inherit from it:
public class AType: GenericType<A>
{ ... }
public class BType: GenericType<B>
{ ... }
...
Lastly, I have another class that wants to contain a list of things that inherit from GenericType, regardless of the value of T, i.e. Atypes, BTypes and so on.
My first attempts were to use List<GenericType> and List<GenericType<Object>> but niether’s given me any joy.
Any tips on how I should be going about this? Much thanks!
So, if I understand correctly, you want something like this:
Which can contain any instance of
AType,BType, etc. You simply do this by makingGenericType<T>itself a subclass ofGenericType:You can then stick any instance into a
List<GenericType>.