Assigning a Null Value

The value of single value Data Fields and Business Objects’ attributes and compositions can be cleared by assigning them the special value, null. If a default value is specified for a Business Object attribute, then assigning null will return the attribute to its default value.

The following diagram and script illustrate this:

// Clear car’s model value (attribute)
myCar.model = null;
// Restore car’s yearBuilt to its default: 1995 (attribute)
myCar.yearBuilt = null;
// Remove car’s roof value (composition)
myCar.roof = null;
// Clear myCar Data Field (Business Object)
myCar = null;
// Clear myInteger Data Field (Integer basic type)
myInteger = null;

For Data Fields or Business Object attributes and compositions that have a multiplicity greater than one, the assignment of null is not possible. Instead, values can be removed using the appropriate List methods. Specifically, remove for the removal of a single specific value, or clear for the removal of all values. This is discussed further in Removing an Item from a List or a Containment Relationship. In the above example, this applies to Car’s wheels composition and the myDates data field.

When dealing with attributes with a multiplicity greater than one, operations that add a null to the list will result in nothing being added, resulting in an unchanged attribute. For example, the following script is equivalent to a no-op, with no changes made to the list.

// Adding null to the list of a car’s wheels does nothing
myCar.wheels.add(null);