As of 2023/JDK21, what @Nullable
to use in Java?
Many online materials don't even mention which import to use. So it is now (dark) history in what order those annotation appeared.
I hope for general answer and from a reputable source (please quote documentation). For JDK21 some article could do as well.
For example javax.annotation.Nullable
may be preferred. But at what version was it introduced? (We use JDK17, maybe next year some projects update to JDK21)
Yet another nullness annotation , JSpecify, was created by a group led by Google:
EISOP Team, Google, JetBrains, Meta , Microsoft , Oracle ,PMD Team , Sonar , Square , Uber , VMware .
They aim to create a tool-independent nullness annotation standard.
They list the reasons to use it in their FAQ
The 1.0.0 release arrived 2024-07. A reference implementation is available now. Presumably, various existing tools will be adding support.
See the thorough documentation and guides available at the JSpecify site.
It seems to me, that jakarta.annotation.Nullable
from jakarta.annotation-api is the closest to being "the standard". The old javax.annotation repo links to its sources and as pointed in the comment, the ever popular checker framework will deal with it.
In terms of adoption, it appears in ~110k files on github as of 06/2024 but I guess this number will still grow as more Servlet projects migrate to newer versions of the spec (javax.annotation.N
currently matches >1M files, hard to guess however how many of them are Servlet related and how many of those will be migrated).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With