java枚举练习
网站首页 文章专栏 java枚举练习
java枚举练习
编辑时间:2019-07-09 09:42 作者:毛毛小妖 浏览量:117 评论数:0
package com.demo.enumTest;

public enum TestEnum {

	ONE(1,"齐","2001"),TWO(2,"楚","2002"),Three(3,"燕","2003"),four(4,"赵","2004"),five(5,"魏","2005"),six(6,"韩","2006");
	
	
	private int code;
	private String name;
	private String year;
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getYear() {
		return year;
	}
	public void setYear(String year) {
		this.year = year;
	}
	
	/**
	 * 构造方法
	 * @param code
	 * @param name
	 * @param year
	 */
	TestEnum(int code, String name,String year) {
		this.code = code;
		this.name = name;
		this.year = year;
	}
	
	/**
	 * 枚举获取
	 * @param code
	 * @return
	 */
	public static TestEnum get(int code){
		TestEnum[] values = TestEnum.values();
		for(TestEnum element : values){
			if(code == element.getCode()){
				return element;
			}
		}
		return null;
	}
	
}

 

推荐文章
来说两句吧
最新评论
    还没有人评论哦,快来坐沙发吧!