声明intDef一次

时间:2017-10-31 14:02:22

标签: java android interface annotations

我在这里读过有关intDef

的内容

https://noobcoderblog.wordpress.com/2015/04/12/java-enum-and-android-intdefstringdef-annotation/

这是一个例子:

public static final int SUNDAY = 0;
public static final int MONDAY = 1;
public static final int TUESDAY = 2;
public static final int WEDNESDAY = 3;
public static final int THURSDAY = 4;
public static final int FRIDAY = 5;
public static final int SATURDAY = 6;

然后为这些常量声明@IntDef,

@IntDef({SUNDAY, MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY})
@Retention(RetentionPolicy.SOURCE)
public @interface WeekDays {}

我如何避免两次写字符串?我不想冒险让其他开发人员在一个地方添加一天,而不是注释会反映变化。

这可能吗?

0 个答案:

没有答案