|
19 | 19 | import java.lang.annotation.*;
|
20 | 20 |
|
21 | 21 | /**
|
22 |
| - * An element annotated with {@link Nullable} claims {@code null} value is perfectly <em>valid</em> |
| 22 | + * An element annotated with {@code Nullable} claims {@code null} value is perfectly <em>valid</em> |
23 | 23 | * to return (for methods), pass to (parameters) or hold in (local variables and fields).
|
24 | 24 | * Apart from documentation purposes this annotation is intended to be used by static analysis tools
|
25 | 25 | * to validate against probable runtime errors or element contract violations.
|
26 | 26 | * <p>
|
27 | 27 | * By convention, this annotation applied only when the value should <em>always</em> be checked against {@code null}
|
28 | 28 | * because the developer could do nothing to prevent null from happening.
|
29 |
| - * Otherwise, too eager {@link Nullable} usage could lead to too many false positives from static analysis tools. |
| 29 | + * Otherwise, too eager {@code Nullable} usage could lead to too many false positives from static analysis tools. |
30 | 30 | * <p>
|
31 |
| - * For example, {@link java.util.Map#get(Object key)} should <em>not</em> be annotated {@link Nullable} because |
| 31 | + * For example, {@link java.util.Map#get(Object key)} should <em>not</em> be annotated {@code Nullable} because |
32 | 32 | * someone may have put not-null value in the map by this key and is expecting to find this value there ever since.
|
| 33 | + * It could be annotated as {@link UnknownNullability} or left unannotated. |
33 | 34 | * <p>
|
34 |
| - * On the other hand, the {@link java.lang.ref.Reference#get()} should be annotated {@link Nullable} because |
| 35 | + * On the other hand, the {@link java.lang.ref.Reference#get()} should be annotated {@code Nullable} because |
35 | 36 | * it returns {@code null} if object got collected which can happen at any time completely unexpectedly.
|
| 37 | + * <p> |
| 38 | + * If a method overrides a superclass method, and the superclass method specifies the nullability on parameter |
| 39 | + * or return type, then the subclass method should specify the same nullability, either directly or indirectly |
| 40 | + * via {@link @NotNullByDefault}. The only exception is the covariant return type nullability: if the superclass |
| 41 | + * method is declared to return nullable value, then subclass may declare to return a not-null value. |
| 42 | + * <p> |
| 43 | + * The tools may issue a warning if the nullability for a subclass method contradicts from the specified nullability |
| 44 | + * of a superclass method. |
| 45 | + * |
| 46 | + * @see NotNull |
36 | 47 | */
|
37 | 48 | @Documented
|
38 | 49 | @Retention(RetentionPolicy.CLASS)
|
|
0 commit comments