JAVA中定義常量的3種方式

來源:互聯網
上載者:User

標籤:

1、最古老的

 //未處理public static final int PROCESS_STATUS_UNTREATED = 0;//已接收public static final int PROCESS_STATUS_ACCPECTED = 1;//已處理public static final int PROCESS_STATUS_PROCESSED = 2;

2、改進版的

public static final class PROCESS_STATUS{        //未處理        public static final int UNTREATED = 0;        //已接收        public static final int ACCPECTED = 1;        //已處理        public static final int PROCESSED = 2;}

3、枚舉版(好處顯而易見,既可以擷取code又能擷取漢字),以後定義常量採用此方法

public static enum PROCESS_STATUS implements KeyValueEnum{        UNTREATED(0,"未處理"),        ACCPECTED(1,"已接收"),        PROCESSED(2,"已處理");        private Integer code;        private String desc;        private PROCESS_STATUS(Integer key , String value){            this.code = key;            this.desc = value;        }        @Override        public Integer getCode() {            return code;        }        @Override        public String getDesc() {            return desc;        }       }

 調用方式:

//擷取編碼PROCESS_STATUS.UNTREATED.getCode();//擷取描述PROCESS_STATUS.UNTREATED.getDes();

 

JAVA中定義常量的3種方式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.