How the null-safe period operator handles null

In contrast to the standard period character operator, the null-safe period operator ?. always returns null if the left side of the operator is null. This works both for accessing properties and for invoking methods. If the left side of the operator is null, Gosu does not evaluate the right side of the expression.

The null-safe operator is particularly important for invoking methods because for methods, the standard period operator throws an exception if the left side of the period is null.

For property access in Gosu, the standard period and the null-safe period operator are equivalent. The period operator is already null-safe.

See also