Recently I started using android's support library IntDef/StringDef (Typedef Annotations). I followed the documentation in Android Tools Project Site and couldn't find there or in any other relevant tutorial how can I use IntDef/StringDef typedef annotations with generics array. for example, assuming I have the following code snippet:
public static final String MEDIA_IMAGE = "image";
public static final String MEDIA_TEXT = "text";
public static final String MEDIA_LINK = "link";
public static final String MEDIA_AUDIO = "audio";
public static final String MEDIA_VIDEO = "video";
public static final String MEDIA_VOICE = "voice";
@StringDef ({MEDIA_IMAGE, MEDIA_TEXT, MEDIA_LINK, MEDIA_AUDIO, MEDIA_VIDEO, MEDIA_VOICE})
@Retention(RetentionPolicy.SOURCE)
public @interface Media {}
I would like to do something similar to this using generics array and typedef annotations:
public List<@Media String> getMediaItems() {
...
}
public void setMediaItems(List<@Media String> mediaItems) {
...
}
However, that seems to be impossible that way.. Since the compiler says:
"Type annotations are not supported at this language level"
Any suggestions?
If you try to do something like private List<@Media String> mList
with JavaVersion.VERSION_1_7
you'll get a
Type annotation are not supported at this language level
Though you can do something like private @Media String[] mArray
.
With JavaVersion.VERSION_1_8
private @Media List<String> mList
will work.
I'll be honest, didn't run to test it, but no Lint error was given.
There is no way you can annotate type parameters in Java - the language does not support this. The only thing you can do with type parameters - is make them bounded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With