Click here to Skip to main content
15,887,404 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using the @Retention and @StringDef annotations for some of my methods in a library and I face a strange warning, I want to understand.

What I have tried:

In a static class, SIP, 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 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 the warning:

The typedef annotation ....toolbox.Tools.ResourceType should have @Retention(RetentionPolicy.SOURCE)

It seems to be uncritical, everything works fine. But can someone please explain me, why Annotation#1 does not get a warning and #2 gets a warning? Both are built identical, both only used in static context. From my point of view, both are the same.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900