Property accessor paths are null safe
One notable
difference between Gosu and some other languages is that property accessor
paths in Gosu are tolerant of unexpected null values. This feature affects
only expressions separated by period characters that access a series
of instance variables or properties such as:
obj.Property1.Property2.Property3In most
cases, if any object to the left of the period character is null, Gosu does not throw a null
pointer exception (NPE) and the expression returns null. Gosu null-safe property
paths tend to simplify real-world code. Gosu null-tolerant property accessor
paths are a very good reason to expose data as properties in Gosu classes
and interfaces rather than as setter and getter methods.
Gosu provides additional null-safe operators. For example, specify default values with code like:
// Set display text to the String in the txt variable, or if it is null use "(empty)"
var displayText = txt ?: "(empty)"
See also
