Which @NotNull Java annotation should I use?

前端 未结 22 2821
梦如初夏
梦如初夏 2020-11-22 02:44

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.

22条回答
  •  再見小時候
    2020-11-22 03:26

    Android

    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) {}
    

提交回复
热议问题