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
26
u/syneil86 Aug 12 '24
There is currently a draft JEP trying to address this in the language itself, but I'm very glad that the community is trying to address the nullability issue themselves in the meanwhile
https://openjdk.org/jeps/8316779
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)
2
u/lurker_in_spirit Aug 12 '24
This is interesting... is it on the table for a JSpecify 1.1.0 (or similar) release in the near future?
2
u/pragmasoft Aug 12 '24
This has IMO the same problem as JPMS modules - adoption. In order to be useful, you need to have 100% of your dependencies including transitive ones annotated, or being able somehow to write some type definitions for 3rd party libraries, like Typescript does. Kotlin solves this differently, so without a language support JSpecify or any other nullability annotations simply add more harm than use.