标签:
public enum TestEnum { IMG,TEXT,WORD }
使用时:
TestEnum testEnum=TestEnum.WORD; System.out.println(testEnum.toString()); //WORD System.out.println(testEnum.ordinal());//2
public enum TestEnum { IMG { public String getType() { return "img"; } }, TEXT { public String getType() { return "text"; } }; public abstract String getType(); }
TestEnum testEnum=TestEnum.TEXT;
System.out.println(testEnum.toString());//TEXT
System.out.println(testEnum.ordinal());//1
System.out.println(testEnum.getType());//text
public enum TestEnum { IMG("a"), TEXT("b"), PIC("c"); private final String value; private TestEnum(String value) { this.value = value; } public String getValue(){ return value; } }
结果是:
TestEnum testEnum=TestEnum.TEXT;
System.out.println(testEnum.toString()); //TEXT
System.out.println(testEnum.ordinal());//1
System.out.println(testEnum.getValue());//b
标签:
原文地址:http://www.cnblogs.com/LiuChunfu/p/5672112.html