|
This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Data Commons 4.1.0! |
Null Safety
One of Kotlin’s key features is null safety, which cleanly deals with null values at compile time.
This makes applications safer through nullability declarations and the expression of “value or no value” semantics without paying the cost of wrappers, such as Optional.
(Kotlin allows using functional constructs with nullable values. See this comprehensive guide to Kotlin null safety.)
|
As of Spring Framework 7 and Spring Data 4, Spring Data uses JSpecify for nullability annotations.
The earlier JSR-305-based |
Although Java does not let you express null safety in its type system, the Spring Data API is annotated with JSpecify annotations.
By default, types from Java APIs used in Kotlin are recognized as platform types, for which null checks are relaxed.
JSpecify annotations provide null safety for the whole Spring Data API to Kotlin developers, with the advantage of dealing with null-related issues at compile time.
See Null Handling of Repository Methods for details on how null safety applies to Spring Data repositories.
| Generic type arguments, varargs, and array element nullability are not supported yet, but should be in an upcoming release. |