public enum Path {
PATH1("/home/acer/logs1"),
PATH2("/home/acer/logs2"),
PATH3("/home/acer/logs3"),
PATH4("/home/acer/logs4");
private String path;
Path(String path) {
this.path = path;
}
public String getPath() {
return path;
}
//测试方法
public static void main(String[] args) {
System.out.println(Path.PATH1.getPath());
System.out.println(Path.PATH2.getPath());
System.out.println(Path.PATH3.getPath());
System.out.println(Path.PATH4.getPath());
}
}
Java 中枚举跟类是差不多的。你可以在枚举中用一个成员变量记录你所谓的“赋值”,参考一下:http://my.oschina.net/u/1583585/blog/263034
枚举不能存字符串