Custom Enum in Java

☆樱花仙子☆ 提交于 2019-12-02 16:38:05

问题


I need to implement custom Enum. It should some class which implements Enum methods like valueOf, values and ordinal without directly extending java.lang.Enum. I have been thinking about creating it in such a way where instead of the String should be some generic type T:

public class CustomEnum {
    private static int size;
    private static final InnerEnum enumValues;

    public CustomEnum(){

    }

    public String valueOf(String innerEnum, String name){
        if(name.equals(innerEnum)){
            return innerEnum;
        }
        return null;
    }

    public InnerEnum values(){
        return enumValues;
    }

    public int ordinal(){}

    public static class InnerEnum{
        public static String[] data;
        public static int number;
    }
}

I should be able to give some varying number of parameters (like using varargs) and create constants out of them plus all the enum methods. But I do not really know how to implement all of it. I would be very grateful if someone would help me with that!

来源:https://stackoverflow.com/questions/47407553/custom-enum-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!