🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators nullValue
This page was created by Alexandra on 2017-08-13. Last edited by Wikiadmin on 2026-07-29.

You can use <Type>.nullValue in OCL and Executable Action Language (EAL) expressions when you need to assign a typed null value to a nullable attribute or variable, or return null from a method.

Syntax

<Type>.nullValue

Replace <Type> with the type of the value you are assigning. Use the typed null value on the right-hand side of an assignment.

someObject.someAttribute := <Type>.nullValue

Clear an attribute

For example, if a Car object has an attribute named Name, assign the null value for the attribute's type to remove its current value:

vCar.Name := <NameType>.nullValue

Here, <NameType> stands for the type of Name. After the assignment, Name has no value.

For clearing a nullable attribute or a single-link association (0..1), you can also use setToNull. For example:

Order.allinstances->first.OrderDate.setToNull

Use setToNull when the intention is specifically to clear the target property. Use <Type>.nullValue when you need a null value in an assignment, variable expression, or return expression.

Assign null to a variable

You can assign a typed null value to a variable when the variable needs to hold no object or value:

vCar := Car.nullValue

In this example, vCar is assigned a null value of type Car.

Return null from a method

A method can return a typed null value when it has no result to return:

return Car.nullValue

The returned null value must have the method's return type.

Do not use nullValue for comparisons

Do not compare a value with <Type>.nullValue.

vCurrent_UppdragTyp = Uppdragstyp.nullValue    -- WRONG

Use .isNull to test whether a value is null, and .notNull to test whether it has a value:

vCurrent_UppdragTyp.isNull
vCurrent_UppdragTyp.notNull

These expressions return Boolean results and can be used where a Boolean condition is required. See OCL Boolean Operators for Boolean expressions and OCL General Operators for finding available operators in the OCL Editor.

See also