android利用注解限定同类型传参

使用注解可实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class PickerType {
public static final int First = 0;
public static final int Second = 1;
public static final int Third = 2;
public static final int Fourth = 3;
//TypeDef注解使用了@interface来声明新的枚举注解类型。其中@IntDef和@StringDef注解以及@Retention标注了新的注解,目的是定义这个枚举类型。而
@IntDef({First, Second, Third, Fourth})
@Retentino(RententionPolicy.SOURCE)注解告诉编译器在生成.class文件时不保留枚举注解数据。
@Retention(RetentionPolicy.SOURCE)
public @interface Type {
}
}