這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)Enum如何在Java項(xiàng)目中運(yùn)用 ,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

首先,定義一個(gè)Enum的類Status,有兩個(gè)屬性statusValue狀態(tài)碼 以及 statusDesc狀態(tài)描述
public enum Status {
STATUS_OK("01","成功"),
STATUS_FAILED("02","失敗"),
STATUS_NOTHING("03","未知狀態(tài)");
private Status(String statusValue, String statusDesc){
this.statusValue = statusValue;
this.statusDesc = statusDesc;
}
//通過statusValue獲取狀態(tài)描述
public static String getStatusDesc(String statusValue){
for(Status s : Status.values()){
if(s.statusValue.equals(statusValue)){
return s.statusDesc;
}
}
return null;
}
//重寫toString方法
@Override
public String toString(){
return "statusValue=" + this.statusValue + ",statusDesc=" + this.statusDesc;
}
private String statusValue;//狀態(tài)值
private String statusDesc;//狀態(tài)描述
public String getStatusValue() {
return statusValue;
}
public void setStatusValue(String statusValue) {
this.statusValue = statusValue;
}
public String getStatusDesc() {
return statusDesc;
}
public void setStatusDesc(String statusDesc) {
this.statusDesc = statusDesc;
}
}
標(biāo)題名稱:Enum如何在Java項(xiàng)目中運(yùn)用-創(chuàng)新互聯(lián)
文章分享:http://chinadenli.net/article32/gespc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、網(wǎng)站維護(hù)、建站公司、網(wǎng)站收錄、網(wǎng)站內(nèi)鏈、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容