@Documented @Retention(value=RUNTIME) @Target(value=TYPE_USE) @SubtypeOf(value=Nullable.class) @MonotonicQualifier(value=NonNull.class) public @interface MonotonicNonNull
Example use cases include lazy initialization and framework-based initialization in a lifecycle method other than the constructor.
A monotonically non-null field has these two properties:
When the field is first read within a method, the field cannot be assumed to be non-null.
After a check that a
@MonotonicNonNull field holds a non-null value, all subsequent
accesses within that method can be assumed to be non-null, even after arbitrary external
method calls that might access the field.
@MonotonicNonNull gives stronger guarantees than
Nullable. After a check that
Nullable field holds a non-null value, only accesses until the next non-
SideEffectFree method is called can be assumed to be
To indicate that a
@Nullable field is non-null whenever a
particular method is called, use
Final fields are treated as MonotonicNonNull by default.