Define overloaded methods and constructors
- Last Updated: October 8, 2020
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Although the use cases for overloading methods and constructors are different, the requirements for defining an overloaded method or constructor are almost the same. To define an overloaded method or constructor, you must do one of the following:
- Define a different number of parameters than any of the others.
- Ensure that at least one common parameter among them has a different
mode (
INPUT,OUTPUTorINPUT-OUTOUT) from any of the others. - Ensure that at least one corresponding parameter among them
has a different data type definition from any of the others. In
addition to basic differences in data type, such as between different
primitive types, different class or interface types, different temp-tables,
and different ProDataSets, differences in data type can take the
following forms:
- For a data type that can be defined as an array, the difference can be whether it is defined as an array or not, whether it is defined as a determinate or indeterminate array, and whether two determinate arrays have different sizes (extents).
- To differentiate static temp-table (
TABLE) or static ProDataSet (DATASET) parameters, parameters of each type must differ in their defined schema. - A dynamic temp-table (
TABLE-HANDLE) or ProDataSet (DATASET-HANDLE) parameter differs from any static temp-table or ProDataSet parameter, respectively. However, you can have only one method or constructor that differs by specifying aTABLE-HANDLErather than aTABLEparameter, or by specifying aDATASET-HANDLErather than aDATASETparameter. In other words, because they have no schema associated with them at compile time, ABL cannot distinguish multipleTABLE-HANDLEparameters from each other or multipleDATASET-HANDLEparameters from each other.
- Finally, for methods, because method scope (specified by the
STATICoption on theMETHODstatement) does not participate in method overloading, you cannot define an instance and static method in a class that have the same method name and signature.
The following example shows a fragment of the sample class, acme.myObjs.CustObj,
including the definitions of two overloaded methods distinguished
by the number of parameters (one compared to none):
|
The following example shows a fragment of the sample class, Main,
including the definitions of two overloaded constructors distinguished
by the number of parameters (one compared to none):
|
For more information on defining parameters for overloaded methods and constructors, see the Parameter definition syntax reference entry in ABL Reference.