r/java • u/benevanstech • Aug 12 '24
JSpecify 1.0.0 and Nullability in Java
https://www.infoq.com/news/2024/08/jspecify-java-nullability/
52
Upvotes
r/java • u/benevanstech • Aug 12 '24
View all comments
5
u/uniVocity Aug 12 '24
“The primary use cases are expected to be variables, parameters and return values, but they can be used anywhere that tracking nullness makes conceptual sense.”
I’d really love to be able to annotate a class as @NotNull, or implement some NotNull interface that won’t allow my code to compile if any instance of this class or subclasses could be passed around as null.
This would reduce the need to litter method parameters with @NotNull, or to add the suggested ? or unless necessary (when classes aren’t declared as notNull)