Casting an object reference parameter
- Last Updated: January 16, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
The following example classes are used by the following
examples to demonstrate the use of the CAST function
to pass INPUT object reference parameters. The
first example class is a super class that defines nothing:
|
The next example class is a subclass that defines its own method, subClassMethod( ):
|
ABL does not, by default, allow an object reference of SuperClass to
be used as an instance of SubClass. For example,
if you try to execute subClassMethod( ) using
the object reference to SuperClass, the method
cannot be found. However, if you know that an object reference to SuperClass in reality
points to an instance of SubClass, you can cast
the reference as SubClass to use it.
The following example demonstrates the use of the CAST function
to pass an INPUT object reference parameter. The Main container
class defines an object reference (mySuper) for
the super class and a method (subParmMethod( ))
that expects an object parameter of type SubClass,
as shown:
|
In the previous example, the constructor instantiates a SubClass object,
but assigns it to the SuperClass object reference.
Using the CAST function, the constructor then invokes subParmMethod( ),
passing the object reference as the SubClass parameter
the method expects and that it actually is. The subParmMethod( ) method
then invokes the subClassMethod( ) method
on the passed object reference.