Java – How to use for @Nullable if I used the lombok @NonNull

annotationsjavanullthird-party-libraries

I am using the lombok @NonNull annotation for some of my fields, parameters and methods, partly for null checking, and also partly for documentation purpose. It is then confusing if I added a @NonNull/@NotNull annotation from other libraries.

Then if I also want to add a @Nullable/@CanNull annotation for some of my code, which one should I use? It doesn't exist in lombok (reasonably). If I declare my own annotation, IDEs may not understand them. If I use these annotations from existing libraries, other @NotNull annotations will also get added, and they may easily lead to using wrong annotations when I want the lombok one.

Best Answer

Related Topic