null - Which @NotNull Java annotation should I use? - Stack Overflow
I wouldn't use anything that is not under the javax
namespace at all (even though I love what Lombok and IntelliJ are doing). Otherwise, you might be creating a dependency on something other than what the run-time gives you for something that is pretty much semantics. Maybe for some projects, that's ok, but that'd be a deal-breaker for me.
I would use javax.validation.constraints.NotNull
because that's already here with Java EE 6.
The javax.annotation.NonNull
might not be here until Java 8 (as Stephen pointed out). And the others are not standard annotations.
It would have been nice if annotations were extensible. That way you could define your own non-null
annotation inheriting/extending from anything. Then when standards get ironed out, all you would have to do would be to redefine your own custom annotation.
Read full article from null - Which @NotNull Java annotation should I use? - Stack Overflow
No comments:
Post a Comment