枚举类的写法与用法

来源:互联网 发布:genbank数据库 编辑:程序博客网 时间:2024/06/06 15:37
package com.sitech.cmap.common.enums;/** * <p>Description:通知类型枚举类型</p> * <p>Copyright:Copyright (c) 2017</p> * <p>Company:SI-TECH </p> * @author zhouxy * @version 1.0 * @createtime 2017年5月18日 下午13:30:01 */public enum NotifyType {SMS("SMS", "sms"), EMAIL("邮件", "email"), MESSAGE("短信", "message");//中文名称private String name;//编码private String code;private NotifyType(String name, String code) {this.name = name;this.code = code;}public String getName() {return name;}public static NotifyType getEnum(String code) {for (NotifyType emu : NotifyType.values()) {if (emu.code.equals(code)) {return emu;}}return null;}public void setName(String name) {this.name = name;}public String getCode() {return code;}public void setCode(String code) {this.code = code;}public static void main(String[] args) {//用法NotifyType.SMS.getClass();}}

原创粉丝点击