问题
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