CreateObjectList
has a generic constraint that its type parameter is a class:
function CreateObjectList<T: class>(...): IList<T>;
Your type parameter does not meet that constraint since it is an interface. The thing about an object list is that it holds objects. If you take a look at TObjectList
in Spring.Collections.Lists
you'll see that it also has the generic constraint that its type parameter is a class. And since CreateObjectList
is going to create a TObjectList<T>
, it must reflect the type constraint.
The raison d'être of TObjectList<T>
is to assume ownership of its members through the OwnsObjects
. Much in the same way as do the classic Delphi RTL classes of the same name. Of course you are holding interfaces and so you simply do not need this functionality. You should call CreateList
instead. A plain TList<T>
is what you need, even if you refer to it through the IList<T>
interface.
LMyList := TCollections.CreateList<IMyObjChild>;