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?
Infer nullityThe analysis helps you detect contract violations in your code and suggests null checks where possible.
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.
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.
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.
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