jdk1.8使用枚举类
package com.mq; import java.util.Arrays; import java.util.HashMap; import java.util.Map; public enum ChannelEnum { WEBB("15","威客巴巴"), CMM("19","菜嬷嬷"); private String channelCode; private String channelName; ChannelEnum(String channelCode, String channelName) { this.channelCode = channelCode; this.channelName = channelName; } public static final Map<String, String> channelEnumMap = new HashMap<>(); static { Arrays.stream(ChannelEnum.values()).forEach(e->channelEnumMap.put(e.getChannelCode(),e.getChannelName())); } public String getChannelCode() { return channelCode; } public String getChannelName() { return channelName; } public void setChannelCode(String channelCode) { this.channelCode = channelCode; } public void setChannelName(String channelName) { this.channelName = channelName; } }