Nullsafe Operator
Learn about the nullsafe operator and how it provides the ability to handle the NULL data type.
The nullsafe operator is used in a chain of object property references. If one of the properties in the chain does not exist (in other words, it is considered NULL
), the operator returns a value of NULL
safely without issuing a warning.
In our example, we must have the following:
An Extended Markup Language (XML) file named
produce.xml
.Lines 4–15: We also need to define a
getQuantity()
function that first checks to see if that property is not empty before proceeding to the next level.Lines 18–30: A code snippet that scans through the XML document and displays quantities.
Get hands-on with 1200+ tech skills courses.