1. 程式人生 > >遍歷列舉類兩種方式小結

遍歷列舉類兩種方式小結

package com.test.enums;
public enum EnumsTest {

	UPDATE(1,"更新"),
	LOGIN(2,"登陸"),
	STOCK_IN(3,"庫存領用"),
	QUERY_ACCOUNT(4,"賬戶查詢"),
	PERSTORE(5,"預存"),
	OPEN_CARD_APPLY(6,"開卡申請"),
	OPEN_CARD(7,"開卡"),
	YIJIETIAO_APPLY(8,"借條申請"),
	ADDED_SERVICE_MAG(9,"增值服務管理"),
	NEW_ACCOUNT(10,"新建賬戶");
	
	private Integer code;
	private String type;
	
	private EnumsTest(Integer code,String type){
		this.code=code;
		this.type=type;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	
	 public static void main(String args[]){
	     System.out.println("第一種通過反射");  
	     Class<EnumsTest> clz=EnumsTest.class;  
	     for(EnumsTest obj:clz.getEnumConstants()){  
	         System.out.println(obj.getType());  
	     }  
	          
	     System.out.println("第二種通過列舉靜態方法values()");  
	        for(EnumsTest rate:EnumsTest.values()){  
	           System.out.println(rate.getType());  
	        }  
	     }  
}