Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Infer Nullity?

While looking at the various options in Android Studio's Analyze tab, I came across an option called "infer nullity". I am just curious how this tool is supposed to be used and what can it do for my Android Studio project?

like image 825
Andre Perkins Avatar asked Mar 25 '14 17:03

Andre Perkins


People also ask

What is infer nullity?

Infer nullityThe analysis helps you detect contract violations in your code and suggests null checks where possible.

How do I get rid of an inferred annotation?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Inlay Hints | Annotations | Java. Select the Inferred annotations checkbox. Apply the changes and close the dialog.

How to add annotations in android Studio?

To enable annotations in your project, add the support-annotations dependency to your library or app. Any annotations you add then get checked when you run a code inspection or lint task.


1 Answers

This option analyses your code and adds @Nullable and @NotNull annotations to your variables and parameters. This assists IntelliJ in detecting contract violations in your code and suggesting null-checks where necessary. To get the full benefit of this feature, you must annotate as much of your code as possible.

The downside of "Infer Nullity" is that, by default, it uses annotations from a JetBrains IntelliJ specific Jar (com.intellij.annotations.NotNull). As of version 10.5 of IntelliJ, there does seem to be some support for using other annotations.

For more information check out the detailed How-To on this feature.

like image 71
AnthonyW Avatar answered Oct 03 '22 22:10

AnthonyW