import java.util.Scanner; public class EnumTestO { /** * @author:lixh */ public static void main(String[] args) { // TODO Auto-generated method stub // System.out.println(Size.SMALL.toString());//返回枚举常量名 // System.out.println(Enum.valueOf(Size.class, "SMALL")); //toString的逆方法是valueOf // Size s = Size.SMALL; // System.out.println(s); /*System.out.println(Size.values()); //包含全部枚举值的数组 for (Size s : Size.values()) { System.out.println(s); System.out.println(s.getAbbString()); //返回构造参数 }*/ // System.out.println(Size.LARGE.ordinal());//返回枚举中常量的位置 //枚举类型的比较直接用 == 就可以了 System.out.println(Size.LARGE.toString() == Size.LARGE.toString());//构造一次 } /** * 枚举类型 */ } enum Size{ SMALL("S"),LARGE("L"); private String abbString; private Size(String abbString) { this.abbString = abbString; } public String getAbbString() { return abbString; } public void setAbbString(String abbString) { this.abbString = abbString; } }