Enums 使用列表类型的变量定义枚举
我正在研究spring启动应用程序,我有一个案例,我想用List作为类型定义enum。但我在传递列表时遇到语法错误。我们是否有解决此语法错误的方法 我的代码Enums 使用列表类型的变量定义枚举,enums,Enums,我正在研究spring启动应用程序,我有一个案例,我想用List作为类型定义enum。但我在传递列表时遇到语法错误。我们是否有解决此语法错误的方法 我的代码 EMAIL("001", "email", "Send To Email"), SMS("002", "slack", "Send To SMS"), EMAIL_SMS("003", "email", "Send to SMS and Email"); private String code; priv
EMAIL("001", "email", "Send To Email"),
SMS("002", "slack", "Send To SMS"),
EMAIL_SMS("003", "email", "Send to SMS and Email");
private String code;
private String description;
private List<String> dest = new ArrayList<>();
NotificationCenterCodeEnum(String code, List<String> dest, String description) {
this.code = code;
this.dest=dest;
this.description = description;
}
您没有将第二个参数作为列表传递:
EMAIL("Code-001", "email", "Send To Email"),
应该是
EMAIL("Code-001", Arrays.asList("email"), "Send To Email"),
您没有将第二个参数作为列表传递:
EMAIL("Code-001", "email", "Send To Email"),
应该是
EMAIL("Code-001", Arrays.asList("email"), "Send To Email"),
试试这个:
enum Notification {
EMAIL("code 1", "description 1", "email-2", "email-2"),
SMS("code 2", "description 2", "num-1", "num-2", "num-3");
Notification(String code, String description, String... dest) {
this.code = code;
this.description = description;
this.dest = dest;
}
private String code;
private String description;
private String[] dest;
// getters ...
}
使用:
试试这个:
enum Notification {
EMAIL("code 1", "description 1", "email-2", "email-2"),
SMS("code 2", "description 2", "num-1", "num-2", "num-3");
Notification(String code, String description, String... dest) {
this.code = code;
this.description = description;
this.dest = dest;
}
private String code;
private String description;
private String[] dest;
// getters ...
}
使用: