声明intdef一次

ecfsfe2w  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(157)

我在这里读过关于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 {}

我如何避免写两次字符串?我不想冒险让其他开发人员在场景中的某个地方添加一天,而不是让注解反映更改。
这可能吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题