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.
This answer is Android specific. Android has support package called support-annotations
. This provides dozens of Android specific annotations and also provides common ones like NonNull
, Nullable
etc.
To add support-annotations package, add the following dependency in your build.gradle:
compile 'com.android.support:support-annotations:23.1.1'
and then use:
import android.support.annotation.NonNull;
void foobar(@NonNull Foo bar) {}