List (Arraylist function): Difference between revisions
m (→Syntax terms) |
mNo edit summary |
||
Line 15: | Line 15: | ||
==Usage notes== | ==Usage notes== | ||
<ul><li>For more information about factory methods, see <var>[[Object variables#Virtual Constructor methods|Virtual Constructor methods]]</var>. | <ul><li>For more information about factory methods, see <var>[[Object variables#Virtual Constructor methods|Virtual Constructor methods]]</var>. | ||
<li>The maximum number of <var class="term"> | <li>The maximum number of <var class="term">items</var> values is 62. | ||
<li><var>List</var> is a constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is null: | <li><var>List</var> is a constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is null: | ||
<p class="code">%al = List(<var class="term"> | <p class="code">%al = List(<var class="term">items</var>) | ||
%al = %(Arraylist):List(<var class="term"> | %al = %(Arraylist):List(<var class="term">items</var>) | ||
%al = %al:List(<var class="term"> | %al = %al:List(<var class="term">items</var>) | ||
</p> | </p> | ||
<b><i>Note: </i></b>If using the second of these syntax options, which explicitly indicates the class, both the collection and item datatypes must be specified exactly as they are on the collection variable's declaration: | <b><i>Note: </i></b>If using the second of these syntax options, which explicitly indicates the class, both the collection and item datatypes must be specified exactly as they are on the collection variable's declaration: | ||
Line 34: | Line 34: | ||
%fib = list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89) | %fib = list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89) | ||
</p> | </p> | ||
<li>The following <var>List</var> call creates a new <var>Arraylist</var> instance whose items are objects of user class | <li>The following <var>List</var> call creates a new <var>Arraylist</var> instance whose items are objects of user class <var class="term">freight</var>: | ||
<p class="code">class freight | <p class="code">class freight | ||
public | public |
Revision as of 14:49, 8 February 2011
Construct and populate a new Arraylist (Arraylist class)
This shared function is a virtual constructor, or factory method, for Arraylistd. List invokes the creation of a new Arraylist instance, then populates that instance with items that are, respectively, the values of the method arguments.
Syntax
%newList = [%(Arraylist Of itemType):]List( itemList)
Syntax terms
%newlist | A declared or existing Arraylist object. |
---|---|
items | A comma-delimited set of values or variables of the same type as specified on the al declaration. Each of these, from left to right, becomes an item in the resultant new Arraylist, al. |
Usage notes
- For more information about factory methods, see Virtual Constructor methods.
- The maximum number of items values is 62.
- List is a constructor and as such can be called with no method object, with an explicit class name, or with an object variable, even if that object is null:
%al = List(items) %al = %(Arraylist):List(items) %al = %al:List(items)
Note: If using the second of these syntax options, which explicitly indicates the class, both the collection and item datatypes must be specified exactly as they are on the collection variable's declaration:
%al is collection Arraylist of longstring %al = %(Arraylist of longstring):List('Jack', 'and', 'Jill')
- You can also use the List method in contexts where an Arraylist object is a method parameter.
- List is available in Sirius Mods version 7.3 and later.
Examples
- The following List method call creates a new Arraylist instance of 11 integer items that begins with 1 and whose subsequent items are, respectively, the sum of the preceding two integers:
%fib is collection arraylist of float %fib = list(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89)
- The following List call creates a new Arraylist instance whose items are objects of user class freight:
class freight public variable a is float variable b is float constructor newf(%a is float, %b is float) end public ... end class ... %ark is arraylist of object freight %ark = list(newf(11, 14), newf(4, 6), newf(9, 77), -
newf(-7, 1234))