public enum Test001 {
EXCEL("C:/TEST.xls", "哈.xls"),
WORD("C:/TEST.DOC", "哦.doc"),
;
private Test001(String templatePath, String fileName) { // 参数分别对应 C:/TEST.xls,哈.xls
System.out.println("init"); // 有多少个枚举就执行多少次构造方法
this.templatePath = templatePath;
this.fileName = fileName;
}
private final String templatePath;
private final String fileName;
public String getTemplatePath() {
return templatePath;
}
public String getFileName() {
return fileName;
}
private static Map<String, Test001> map = new HashMap<String, Test001>();
static {
for (Test001 in : Test001.values()) { // 把Test001中所有枚举都存放到 map中
map.put(in.name(), in);
}
};
public static Test001 get(String name) {
return map.get(name);
}
public static void main(String[] args) {
Test001 t = Test001.get("EXCEL");
String name = t.getFileName();
String path = t.getTemplatePath();
System.out.println(name);
System.out.println(path);
}
EXCEL("C:/TEST.xls", "哈.xls"),
WORD("C:/TEST.DOC", "哦.doc"),
;
private Test001(String templatePath, String fileName) { // 参数分别对应 C:/TEST.xls,哈.xls
System.out.println("init"); // 有多少个枚举就执行多少次构造方法
this.templatePath = templatePath;
this.fileName = fileName;
}
private final String templatePath;
private final String fileName;
public String getTemplatePath() {
return templatePath;
}
public String getFileName() {
return fileName;
}
private static Map<String, Test001> map = new HashMap<String, Test001>();
static {
for (Test001 in : Test001.values()) { // 把Test001中所有枚举都存放到 map中
map.put(in.name(), in);
}
};
public static Test001 get(String name) {
return map.get(name);
}
public static void main(String[] args) {
Test001 t = Test001.get("EXCEL");
String name = t.getFileName();
String path = t.getTemplatePath();
System.out.println(name);
System.out.println(path);
}