™ does not support output parameters, methods are normally limited to returning a single value. However, in many cases it is useful to return multiple values from a single method. In these cases, the API uses Holder objects
. Holder objects contain a single member variable called value
. Holder objects have no methods.
Holder objects are objects that are created with a single variable. These objects can then be passed into a method that sets that variable. When the method returns, the value of variable can be retrieved.
The following table lists the holder types that are available, the data type of each holder's variable, and the class that you must import to use the holder:
Table 1. Holder objects and data types
|ShortListHolder||Short [ ]||com.PureEdge.ShortListHolder|
|StringListHolder||String [ ]||com.PureEdge.StringListHolder|
Some methods in the FCI library require an IFSUserDataHolder as a parameter, but you do not need to manipulate this object.
Each Holder class provides two constructors.
- An empty constructor that creates an object and declares an empty member variable called value. For example, to create an empty IntHolder use the following constructor:
IntHolder myInt = new IntHolder();
- A constructor that creates an object, declares a variable called value, and sets the value of the variable. For example, to create an IntHolder object with a value of 5, use the following constructor:
IntHolder myInt = new IntHolder(5);
Getting and setting values of Holder objects
To get or set the value of a particular Holder object, dereference the holder's value. For example:
Parent topic: Java API
int value = myIntHolder.value;
myIntHolder.value = 2;