相关疑难解决方法(0)

消除重复的枚举代码

我有大量实现此接口的枚举:

/**
 * Interface for an enumeration, each element of which can be uniquely identified by it's code
 */
public interface CodableEnum {

    /**
     * Get the element with a particular code
     * @param code
     * @return
     */
    public CodableEnum getByCode(String code);

    /**
     * Get the code that identifies an element of the enum
     * @return
     */
    public String getCode();
}
Run Code Online (Sandbox Code Playgroud)

一个典型的例子是:

public enum IMType implements CodableEnum {

    MSN_MESSENGER("msn_messenger"),
    GOOGLE_TALK("google_talk"),
    SKYPE("skype"),
    YAHOO_MESSENGER("yahoo_messenger");

    private final String code;

    IMType (String code) { …
Run Code Online (Sandbox Code Playgroud)

java enums enumeration

22
推荐指数
3
解决办法
7381
查看次数

标签 统计

enumeration ×1

enums ×1

java ×1