Try OpenEdge Now
skip to main content
Object-oriented Programming
Overloaded Method and Constructor Calling Scenarios : Parameters matching widened data types
 

Parameters matching widened data types

ABL always searches for an exact parameter match, but if none is found, it will accept the closest parameter match according to widening in the available method or constructor overloads at compile time. Failure to find a match raises a compile-time error. For more information on matching parameter data types with widening, see the Parameter passing syntax reference entry in OpenEdge Development: ABL Reference.
The examples that follow show how widening can resolve calls to overloaded methods (or constructors):
CLASS Widening:
/* 1 */ METHOD PUBLIC VOID setVal (INPUT piVal AS INTEGER):
        END METHOD.

/* 2 */ METHOD PUBLIC VOID setVal (INPUT pdVal AS DECIMAL):
        END METHOD.
END CLASS.
When the following procedure calls the setVal( ) method with a given parameter, the overloaded method definition that it matches corresponds to the bold-faced number referenced in the comments:
DEFINE VARIABLE rWid   AS CLASS Widening      NO-UNDO.

DEFINE VARIABLE iVal   AS INTEGER INITIAL 42  NO-UNDO.
DEFINE VARIABLE i64Val AS INT64   INITIAL 42  NO-UNDO.
DEFINE VARIABLE dVal   AS DECIMAL INITIAL 4.2 NO-UNDO.

rWid = NEW Widening( ).

rWid:setVal(iVal).   /* Calls 1 - matches exactly                 */
rWid:setVal(i64Val). /* Calls 2 - INT64 matches the wider DECIMAL */
rWid:setVal(dVal).   /* Calls 2 - matches exactly                 */