Package org.antlr.v4.runtime.misc
Annotation Interface NotNull
@Documented
@Retention(CLASS)
@Target({FIELD,METHOD,PARAMETER,LOCAL_VARIABLE})
public @interface NotNull
This annotation marks a field, parameter, local variable, or method (return
value) as never being
null. The specific semantics implied by this
annotation depend on the kind of element the annotation is applied to.
- Field or Local Variable: Code reading the field or local
variable may assume that the value is never
null. Code writing to the field or local variable should ensure that anullreference is never written. - Parameter: Code calling the method should never pass
nullfor this parameter. The implementation may assume that the value is nevernull, and the behavior of the method if the parameter isnullis undefined. Overriding methods may optionally use theNullableannotation instead of this annotation for the parameter, indicating that the overriding method provides additional code to handle anullreference passed for the parameter. - Method (Return Value): Code calling the method may
assume that the result of the method is never
null. The implementation of the method should ensure that anullreference is never returned.
The NullUsageProcessor annotation processor validates certain usage
scenarios for this annotation, with compile-time errors or warnings reported
for misuse. For detailed information about the supported analysis, see the
documentation for NullUsageProcessor.