@Documented
@Retention(value=CLASS)
@Target(value={METHOD,FIELD,PARAMETER,LOCAL_VARIABLE,TYPE_USE})
public @interface NotNull
null
value is forbidden
to return (for methods), pass to (parameters) and hold (local variables and fields).
Apart from documentation purposes this annotation is intended to be used by static analysis tools to validate against probable runtime errors and element contract violations.
If a field is annotated as @NotNull
it's expected to be initialized during object construction.
Tools may issue a warning if it's not the case.
If a method overrides a superclass method, and the superclass method specifies the nullability on parameter
or return type, then the subclass method should specify the same nullability, either directly or indirectly
via NotNullByDefault
. The only exception is the covariant return type nullability: if the superclass
method is declared to return nullable value, then subclass may declare to return a not-null value.
The tools may issue a warning if the nullability for a subclass method contradicts from the specified nullability of a superclass method.
Nullable
public abstract java.lang.String value
public abstract java.lang.Class<? extends java.lang.Exception> exception
By default, IllegalArgumentException
is thrown on null method arguments and
IllegalStateException
— on null return value.