List animals =
creator.CreateAnimals(5);
In the above line from your example, animalType
and type
are run time variables, not types, so this is of course nonsense. A generic version only makes sense, if you know the types at compile time, e.g.:
List animals =
creator.CreateAnimals(5);
where you'd have to constraint types accordingly. If the types are not known, you have to rely completely on reflection...