First of all, anytype variables accept the type assigned to it first, you cannot change it later:
static void Job2(Args _args) { anytype iVar; iVar = 1; //Works, iVar is now an int! iVar = "abc"; //Does not work, as iVar is now bound to int, assigns 0 info(iVar); }
Returning to the first question, new List(Types::AnyType) will never work, since the addEnd method checks the type of its argument at run time, and anytype variables will have the type of the value assigned to it.
Also new List(Types::Object) will store objects, not simple data types like int and str . This may contradict your opinion (and C #), but simple types are not objects.
What is left? Containers:
static void TestList(Args _args) { List collection = new List(Types::Container); ListIterator iter; int iVar; str sVar; Object oVar; container c; ; iVar = 1; sVar = "abc"; oVar = new Object(); collection.addEnd([iVar]); collection.addEnd([sVar]); collection.addEnd([oVar.toString()]); iter = new ListIterator(collection); while (iter.more()) { c = iter.value(); info(conPeek(c,1)); iter.next(); } }
Objects are not automatically converted to containers, usually you provide the pack and unpack methods (implementing the SysPackable interface). The code above uses toString , which is cheating.
On the other hand, I see no use case for your request that lists should contain any type. This contradicts its purpose; the list contains one and only one type defined when creating the List object.
In addition to lists, there are other types of collections , perhaps Struct will suit your needs.