Eclipse has the @NonNullByDefault
annotation, which treats all values as @NonNull
unless you explicitly annotate them as @Nullable
.
Is there an equivalent option in IntelliJ IDEA, or do you have to always use @Nonnull
?
You can also annotate a particular file from the file history view. In the History tab, select the file version you want to review, right-click the corresponding line and select Annotate from the context menu.
The @Nullable annotation helps you detect: Method calls that can return null. Variables (fields, local variables, and parameters), that can be null.
@NonNull – The compiler can determine cases where a code path might receive a null value, without ever having to debug a NullPointerException. @ReadOnly – The compiler will flag any attempt to change the object. This is similar to Collections.
Inferred annotations These annotations can help you better understand code contacts and make code analysis more efficient. IntelliJ IDEA infers the @Nullable and @NotNull annotations that you can use to analyze your source code to spot places where you overlooked null.
Idea version 14 will include support for the JSR 305 "@TypeQualifierDefault" annotation, which allows the user to create a custom annotation, to be used on a package declaration in a package-info.java file, that specifies that everything in that package (not just parameters, but method return values, local variables, etc.) will be implicitly annotated as not allowing null values.
Unfortunately, this doesn't (currently) recursively affect subpackages, so each subpackage has to have a package-info.java file too, declaring that subpackage to use the annotation.
See here for details and an example of use:
http://youtrack.jetbrains.com/issue/IDEA-125281
Note that this is already implemented in Early Access Program (EAP) builds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With