书写枚举类的范例

package com.lpy.enums;

public enum BGMOperatorTypeEnum {
	
	ADD("1", "添加bgm"),				
	DELETE("2", "删除bgm");		
	
	public final String type;
	public final String value;
	
	BGMOperatorTypeEnum(String type, String value){
		this.type = type;
		this.value = value;
	}
	
	public String getUserType() {
		return type;
	}  
	
	public String getValue() {
		return value;
	} 
	
	public static String getValueByKey(String key) {
		for (BGMOperatorTypeEnum type : BGMOperatorTypeEnum.values()) {
			if (type.getUserType().equals(key)) {
				return type.value;
			}
		}
		return null;
	}
	
}

猜你喜欢

转载自blog.csdn.net/Richard_666/article/details/85118322