22= Null-safety
33
44Although Java does not allow to express null-safety with its type system, Spring Framework
5- now provides annotations declared in the `org.springframework.lang` package to declare
6- nullability of APIs and fields.
5+ now provides annotations to declare nullability of APIs and fields.
76
8- Spring Framework leverages these annotations, but they can also be used in any Spring based
7+ Spring Framework leverages itself these annotations, but they can also be used in any Spring based
98Java project to declare null-safe APIs and optionally null-safe fields. Nullability of
109types used inside method bodies is outside of the scope of this feature.
1110
@@ -15,6 +14,11 @@ warnings to Java developers related to null-safety in order to avoid `NullPointe
1514at runtime. JSR 305 meta-annotations allows tooling vendors to provide null-safety support
1615in a generic way, without having to hard-code support for Spring annotations.
1716
17+ [NOTE]
18+ ====
19+ It is not necessary nor recommanded to have JSR 305 dependency in user project classpath.
20+ ====
21+
1822They are also used by Kotlin which supports natively
1923https://kotlinlang.org/docs/reference/null-safety.html[null-safety]. By default, types from
2024Java APIs used in Kotlin are recognized as
@@ -31,7 +35,7 @@ Other libraries like Reactor or Spring Data leverage these annotations as well t
3135null-safe APIs.
3236====
3337
34- The following annotations are provided:
38+ The following annotations are provided in the `org.springframework.lang` package :
3539
3640 * {api-spring-framework}/lang/NonNull.html[`@NonNull`] annotation where specific parameter,
3741 return value, generic type argument, varargs element, array element or field cannot be `null`
0 commit comments