Abstract enum class
public abstract class AbstractEnum { private final String name; private static int nextOrdinal = 0; private final int ordinal = nextOrdinal++; protected AbstractEnum(String name){ this.name = name; } public String getName(){ return this.name; } public int getOrdinal(){ return this.ordinal; } //override equals method public boolean equals(Object o){ AbstractEnum objE = (AbstractEnum) o; return ( this.ordinal == objE.getOrdinal() ); } }
The implementation class for Day enum.
public class DayImpl extends AbstractEnum { protected DayImpl(String name) { super(name); // TODO Auto-generated constructor stub } //creating your enum public static final DayImpl Mon = new DayImpl("monday"); public static final DayImpl Tue = new DayImpl("tuesday"); public static final DayImpl Wed = new DayImpl("wednesday"); public static final DayImpl Thur = new DayImpl("thursday"); public static final DayImpl Fri = new DayImpl("friday"); public static final DayImpl Sat = new DayImpl("saturday"); public static final DayImpl Sun = new DayImpl("sunday"); }
No comments:
Post a Comment