Which @NotNull Java annotation should I use?

前端 未结 22 3211
梦如初夏
梦如初夏 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:37

    For Android projects you should use android.support.annotation.NonNull and android.support.annotation.Nullable. These and other helpful Android-specific annotations are available in the Support Library.

    From http://tools.android.com/tech-docs/support-annotations:

    The support library itself has also been annotated with these annotations, so as a user of the support library, Android Studio will already check your code and flag potential problems based on these annotations.

提交回复
热议问题