一個案子通常都會定義一些Constants也就是"常數"來共用

而裡頭通常也會包含enum 類別

 

XXXConstants.java:

 

public class XXXConstants { 

 //系統Y與N
   public static String YES = "Y"; 
   public static String NO = "N";

// 0啟用,1停用,2已售完
   public static enum ORDER_STATUS{
   啟用,停用,已售完,其它
}

  public static String AAML_STATUS_SEND = "0"; //0已建立
  public static String AAML_STATUS_SEND_SUCCESS = "1"; //1傳送成功

 

}

 

test_main.java:

 

import cc.openhome.web.XXXConstants.ORDER_STATUS;

 

public class test_main {
 
    public static void main(String[] args) throws Exception {
 

    ORDER_STATUS b = findOrderStatus(4);
    System.out.println(b);   // output: 其它

    ORDER_STATUS a = findOrderStatus(0);
    System.out.println(a);   // output: 啟用

   ORDER_STATUS c = findOrderStatus(1);
    System.out.println(c);   // output: 停用

 

 
    }
 
   
   public static ORDER_STATUS findOrderStatus(int intType){
      ORDER_STATUS rtn = null;
      try{
         rtn = ORDER_STATUS.values()[intType];
      }catch(Exception e)
      {
         rtn = ORDER_STATUS.其它;
      }
         return rtn;
   }
 
}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JoshS 的頭像
    JoshS

    JoshS的部落格

    JoshS 發表在 痞客邦 留言(0) 人氣()