Daniel Aguilar · Jul 13, 2021

Method return List of type

Good afternoon I am making a method of a class that I want to return a list of objects of another class that I have defined, example:

ClassMethod myMethod() As list of MyPackage.MyClass

But it gives me a syntax error, I try this and it works:

ClassMethod myMethod() As %ListOfObjects

But I would like to keep the typing.

Is there a way?

Product version: Caché 2018.1
0 136
Discussion (5)2
Log in or sign up to continue

Keep the second version

and build that List of objects with - As list of MyPackage.MyClass


and so on..

Please feel free to send me sample code and I can make it for you too. 

Thanks Neerav I will do it like this

ObjectScript variables are untyped, so preserving the type isn't necessary.

You'll build the list by adding your MyPackage.MyClass objects to it, then you'll return the %ListOfObjects, then you'll use that list's methods to manipulate those objects. For instance, set mything = mylist.GetAt(1) will give you an object that is identical to the MyPackage.MyClass object you put in the list with all of its properties an methods.