android @Nullable注释

时间:2013-03-04 11:40:02

标签: android

我想创建

  

android @Nullable注释

我查看这两个链接,例如

http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/Nullable.html http://code.google.com/p/google-guice/wiki/UseNullable

但没有在android中有效,因为RetentionPolicy,ElementType无效

如何在android中创建@Nullable注释?

2 个答案:

答案 0 :(得分:2)

在项目库中包含jsr-305 jar file。将@nullable与字段一起使用,RoboGuice将停止抱怨空对象。

答案 1 :(得分:2)

对于Android Studio:

  • 将以下内容添加到 build.gradle

    dependencies {
        ...
        // For @Nullable/@NonNull
        compile 'com.android.support:support-annotations:+'
    }
    
  • 转到文件 / 设置项目设置检查并搜索“可空”

    恒定条件&例外 @NotNull / @Nullable问题,点击配置注释并选择Android的注释。

    您可能还想检查常量条件&条件下的建议@Nullable注释... 。例外,或者可能调整其他选项。

相关问题