Use the safe navigation operator (?:)
- Last Updated: February 15, 2022
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
The Safe Navigation Operator (?:) allows you to write code expressions that involve conditional execution of a chain of object-oriented ABL cascading element references in a short-hand way. It simplifies code navigation through chained code elements such as objects, object properties, and methods which may potentially return null references. You can use the Safe Navigation Operator and eliminate elaborate conditional code to validate the return of each element in the chain.
For example, consider the following chained expression:
retVal = Handle:method1():method2():method3().
retVal = Handle?:method1()?:method2()?:method3().Syntax
|
- object-reference
- Reference to an instance of an ABL class that defines the specific data member as an instance member (non-static).
- class-member-name
- The name of a data member or member method you want to access. A class member is an element that is defined in and at the level of a class definition.
Example: Single chain
object-reference?:class-member-name
|
|
Example: Multiple chain
object-reference?:identifier1?:identifier2?:identifier3
|