I\'m looking to make my code more readable as well as use tooling like IDE code inspection and/or static code analysis (FindBugs and Sonar) to avoid NullPointerExceptions.
If you are working on a big project, you may be better of creating your own @Nullable
and/or @NotNull
annotations.
For example:
@java.lang.annotation.Documented
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)
@java.lang.annotation.Target({java.lang.annotation.ElementType.FIELD,
java.lang.annotation.ElementType.METHOD,
java.lang.annotation.ElementType.PARAMETER,
java.lang.annotation.ElementType.LOCAL_VARIABLE})
public @interface Nullable
{
}
If you use the correct retention policy, then the annotations won't be available at runtime. From that point of view, it is just an internal thing.
Even though this is not a strict science, I think it makes most sense to use an internal class for it.
@Nullable
/@NotNull
annotations.How to configure this in IntelliJ ?
Click the "police officer" in the lower right corner of the IntelliJ status bar. And click "Configure inspections" in the popup. Next ...