java 枚举 enum
1.定义
public enum MySex {
man("man"),
woman("nu");
String value ;
MySex(String s){
value = s ;
}
}
2.使用
public class test{
public static void main(String args[]){
MySex ms = MySex.man ;
System.out.println("MySex.man ----->" + ms) ;
System.out.println("ms.str ------->" + MySex.man.value) ;
System.out.println("ms.str ------->" + MySex.woman) ;
System.out.println("ms.str ------->" + MySex.woman.value) ;
}
}
3.打印结果
MySex.man ----->man
ms.str ------->男
ms.str ------->woman
ms.str ------->女