1. 程式人生 > >java列舉類示例

java列舉類示例

看完這個,你就知道列舉可以怎麼定義屬性和方法了

public enum TBSHOP_TYPE {

 TBSHOP_c0("C0-xx","xx專賣店"),
 TBSHOP_C1("C1-xx","xx折扣店"),
 TBSHOP_C2("C2-xx","xx票務店"),
 TBSHOP_C3("c3-xx","xx成都店");
      
 private String typeCode;
 private String desc;
      
 TBSHOP_TYPE(String typeCode,String desc){
    this.typeCode
= typeCode; this.desc= desc; }
 public String getTypeCode() {
    return typeCode;
 }
 public void setTypeCode(String typeCode) {
    this.typeCode = typeCode;
 }

 public String getDesc() {
    return desc;
 }
 public void setDesc(String desc) {
    
this.desc = desc;  }
 public static String getCodeByName(String name) {
    for (TBSHOP_TYPE item : TBSHOP_TYPE.values()) {
       if (item.name().equals(name)) {
          return item.getTypeCode();
       }
    }
    return "";
 }
 public static 
String getCnDescByName(String name) {  for (TBSHOP_TYPE item : TBSHOP_TYPE.values()) {  if (item.name().equals(name)) {  return item.getDesc();  }  }  return "";  } }