Safe calls in chains - Null safety

Safe calls are useful in chains. For example, if Bob, an Employee, may be assigned to a Department (or not), that in turn may have another Employee as a department head, then to obtain the name of Bob's department head (if any), you write the following:

bob?.department?.head?.name

Such a chain returns null if any of the properties in it is null.

Comments

Popular Posts