Android Support Annotation "must have @Retention (RetentionPolicy.SOURCE)"

I use @Retention and @StringDef for some of my methods in the library, and I come across a strange warning that I want to understand.

In the static SIP class, I use this annotation:

 public static final String CODEC_SPEEX_16K = "speex/16000/1"; public static final String CODEC_SPEEX_8K = "speex/8000/1"; public static final String CODEC_SPEEX_32K = "speex/32000/1"; public static final String CODEC_ILBC_8K = "iLBC/8000/1"; public static final String CODEC_GSM_8K = "GSM/8000/1"; public static final String CODEC_PCMU_8K = "PCMU/8000/1"; public static final String CODEC_PCMA_8K = "PCMA/8000/1"; public static final String CODEC_G722_16K = "G722/16000/1"; @Retention(RetentionPolicy.CLASS) @StringDef({ CODEC_SPEEX_16K, CODEC_SPEEX_8K, CODEC_SPEEX_32K, CODEC_ILBC_8K, CODEC_GSM_8K, CODEC_PCMU_8K, CODEC_PCMA_8K, CODEC_G722_16K }) public @interface CodecName {} 

which compiles fine, without any warnings.

In the static class of Tools I use this annotation:

 public static final String RES_TYPE_STRING = "string"; public static final String RES_TYPE_DRAWABLE = "drawable"; public static final String RES_TYPE_LAYOUT = "layout"; public static final String RES_TYPE_VIEW = "id"; public static final String RES_TYPE_DIMEN = "dimen"; public static final String RES_TYPE_COLOR = "color"; public static final String RES_TYPE_ANIM = "anim"; public static final String RES_TYPE_MIPMAP = "mipmap"; @Retention(RetentionPolicy.CLASS) @StringDef({ RES_TYPE_STRING, RES_TYPE_DRAWABLE, RES_TYPE_LAYOUT, RES_TYPE_DIMEN, RES_TYPE_COLOR, RES_TYPE_ANIM, RES_TYPE_VIEW, RES_TYPE_MIPMAP }) public @interface ResourceType { } 

and I get a warning:

In the annotation typedef .... toolbox.Tools.ResourceType should be @Retention (RetentionPolicy.SOURCE)

It seems to be uncritical, everything is working fine. But can someone please explain to me why

Annotation # 1 does not receive a warning;

Annotation # 2 receives a warning;

Both are built in the same way, both are used only in a static context. In my opinion, they are both the same.

+6
source share

All Articles