https://developer.android.com/reference/android/support/annotation/IntDef.html
I'm looking for an example how to define a local variable.
I see how to create a function return, a member variable, a function parameter, but no example to assign a local variable using the Android annotated element @IntDef.
Thanks
UPDATE
Here's one example of what is not working. Does this have something to do with where to put the @Retention? I don't understand how the compiler knows what to apply the Retention Policy to. Is this a global setting?
int foobar() {
@IntDef({
ItemType.TYPE1,
ItemType.TYPE2
})
@Retention(RetentionPolicy.SOURCE)
@interface ItemType {
int TYPE1 = 0;
int TYPE2 = 1;
}
@ItemType int type = TYPE1;
...
}
Another example that doesn't work for me:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final @View.MeasureSpec.MeasureSpecMode int heightMode = MeasureSpec.getMode(heightMeasureSpec);
...
@IntDef({
ItemType.TYPE1,
ItemType.TYPE2
})
public @interface ItemType {
int TYPE1 = 0;
int TYPE2 = 1;
}
// use it in global variable like
@ItemType
private int type;
// use it in local variable like
public void add(@ItemType int type){
}
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