我在项目中定义了这个枚举:
public enum MenuAlertEnum {
DAILY_PLUS (1, "MENU_DAILY_PLUS"),
DAILY_MINUS (2, "MENU_DAILY_MINUS"),
WEEKLY_PLUS (3, "MENU_WEEKLY_PLUS"),
WEEKLY_MINUS (4, "MENU_WEEKLY_MINUS"),
FORTNIGHTLY_PLUS (5, "MENU_FORTNIGHTLY_PLUS"),
FORTNIGHTLY_MINUS (6, "MENU_FORTNIGHTLY_MINUS"),
MONTHLY_PLUS (7, "MENU_MONTHLY_PLUS"),
MONTHLY_MINUS (8, "MENU_MONTHLY_MINUS");
private final int id;
private final String alertName;
private MenuAlertEnum(int id, String alertName) {
this.id = id;
this.alertName = alertName;
}
public int getId() {
return id;
}
public String getAlertName() {
return alertName;
}
}
,我必须将其添加到List<String>
中,但我不知道是否可以像这样一枪完成:
List<String> menuPrice = new ArrayList<String>();
menuPrice.addAll(MenuAlertEnum.values());