Qualifier for a type in a method signature or a local variable declaration:
The entity (return value, parameter, field, local variable) whose type has this
annotation can never have the value
null
at runtime.
This has two consequences:
- Dereferencing the entity is safe, i.e., no
NullPointerException
can occur at runtime.
- An attempt to bind a
null
value to the entity is a compile time error.
For the second case, diagnostics issued by the compiler should distinguish three situations:
- Nullness of the value can be statically determined, the entity is definitely bound from either of:
- the value
null
, or
- an entity with a
@Nullable
type.
- Nullness cannot definitely be determined, because different code branches yield different results.
- Nullness cannot be determined, because other program elements are involved for which
null annotations are lacking.