遍历枚举类两种方式小结

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 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());  
	        }  
	     }  
}


 
 

你可能感兴趣的:(Java)