“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)
It's actually very rare to need to write `@NonNull`. We almost didn't even include it in the jar! Just put `@NullMarked` on your class/package/module instead.
Are there any examples available that show how to specify @NullMarked at the package or module level? I've combed through the JSpecify docs, but haven't found any.
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)