月眸


java枚举练习

毛毛小妖 2019-06-23 142浏览 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;
	}
	
}

 

最后修改:2019-06-23 10:24:27 © 著作权归作者所有
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

上一篇

发表评论

说点什么吧~

评论列表

还没有人评论哦~赶快抢占沙发吧~