Annotation 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 a null reference is never written.
  • Parameter: Code calling the method should never pass null for this parameter. The implementation may assume that the value is never null, and the behavior of the method if the parameter is null is undefined. Overriding methods may optionally use the Nullable annotation instead of this annotation for the parameter, indicating that the overriding method provides additional code to handle a null reference 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 a null reference 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.