Annotation Interface NonNullByDefault


@Documented @Retention(CLASS) public @interface NonNullByDefault
Applying this annotation to a declaration has the effect that type references, which are contained in the declaration, and for which a null annotation is otherwise lacking, should be considered as @NonNull.
Locations
This annotation is permitted for these declarations: PACKAGE, TYPE, METHOD, CONSTRUCTOR, FIELD, LOCAL_VARIABLE.
Fine tuning
The exact effect is further controlled by the attribute value(), specifying what kinds of locations within the given declaration will be affected. See DefaultLocation for the meaning of the available values.
Nested defaults
If this annotation is applied to a declaration that is already affected by the same annotation at an enclosing scope, the inner annotation replaces the effect of the outer annotation for the scope of the inner declaration.
Canceling a default
In particular, specifying an empty value ({}) for the value() attribute has the effect of canceling any null defaults that might be defined for any enclosing scope.

Note that for applying an annotation to a package, a file by the name package-info.java is used.

Note: Since org.eclipse.jdt.annotation 2.0.0, this annotation also applies to field and local variable declarations and since 2.2.0 also to parameter and module declarations. For the old API, see @NonNullByDefault in 1.1.0.

Since:
1.0
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Specifies the set of locations within the annotated declaration that should be affected by the nonnull default.
  • Element Details

    • value

      Specifies the set of locations within the annotated declaration that should be affected by the nonnull default.
      Returns:
      the locations, or an empty array to cancel any null defaults from enclosing scopes
      Since:
      2.0
      Default:
      {PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT}