Skip to content

Commit 61bce51

Browse files
committed
NotNullByDefault: refine the behavior for type parameters
1 parent 0c06dec commit 61bce51

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/jvmMain/java/org/jetbrains/annotations/NotNullByDefault.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,21 @@
2121
* The tools may issue a warning if the nullability for a subclass method contradicts from the specified nullability
2222
* of a superclass method.
2323
* <p>
24-
* The annotation has no effect on newly declared type parameters and their bounds. Only instantiations of
25-
* type parameters are constrained.
24+
* For newly declared type parameters, the annotation applies to its bounds, including implicit {@code Object}
25+
* bound if no explicit bound is declared. For example, {@code <T>} declared under {@code @NotNullByDefault} scope
26+
* means the same as {@code <T extends @NotNull Object>}. To reset to default behavior in this case, one should use
27+
* {@code <T extends @UnknownNullability Object>}.
28+
* <p>
29+
* The type parameter references are not affected by {@code @NotNullByDefault}. For example:
30+
* <pre>{@code
31+
* @NotNullByDefault
32+
* interface Pair<K extends @Nullable Object, V> {
33+
* // Not assumed to be @NotNull; may return null depending on the T instantiation
34+
* K getKey();
35+
* // Returns @NotNull, as implicit upper bound of V is @NotNull Object,
36+
* // so it cannot be instantiated with a nullable type
37+
* V getValue();
38+
* }}</pre>
2639
* <p>
2740
* The annotation has no effect on local variables.
2841
*

0 commit comments

Comments
 (0)