@ParametersAreNonnullByDefault annotation helps you define that all method parameters in a class or a package have
@NotNull semantic, unless they are explicitly annotated with the
@ParametersAreNonnullByDefault annotation can be used with a package, a class, or a method.
To use the annotation, add the
jsr305 library to module dependencies:
Open the Project Structure dialog (Ctrl+Shift+Alt+S), and go to .
Click Add and select .
In the IntelliJ IDEA home directory, select lib\jsr305.jar.
(Optionally) In the next dialog, you can modify library name and level.
Apply the changes and close the dialog.
Once you add the JAR to your project, you can start using the
@ParametersAreNonnullByDefault annotation. For example, consider the following code:
If you annotate the
sort() method with
@ParametersAreNonnullByDefault, IntelliJ IDEA immediately recognizes that
if statement is extraneous, and reports about the condition that is always true.
However, if you annotate the parameter of the method
sort() as nullable, you will see no inspection messages.