I need several enumerations that have the same fields, constructors, and methods, but different sets of values. I know that enums cannot be inherited in the forehead, but does anyone know how to emulate something like this:
enum Parent { DUMMY_ITEM("", 0); String otherName; int intValue; Parent(String otherName, int intValue) { this.intValue = intValue; this.otherName = otherName; } void setIntValue(int value) { intValue = value; } int getIntValue() { return intValue; } int calcSomething() { return intValue * otherName.length(); } } enum Child1 extends Parent { ACTUAL_CHILD1_ITEM1("CHILD1_ITEM1", 1), ACTUAL_CHILD1_ITEM2("CHILD1_ITEM2", 1), ACTUAL_CHILD1_ITEM3("CHILD1_ITEM3", 1), } enum Child2 extends Parent { ACTUAL_CHILD2_ITEM1("CHILD2_ITEM1", 1), ACTUAL_CHILD2_ITEM2("CHILD2_ITEM2", 1), ACTUAL_CHILD2_ITEM3("CHILD2_ITEM3", 1), } So that you can write int i = ACTUAL_CHILD2_ITEM1.getIntValue() , int j = ACTUAL_CHILD1_ITEM3.calcSomething() , etc. It’s ugly to repeat the same code of methods and all fields in different enumerations many times, but you really want to use different sets of values so that they are not confused, and that the IDE prompts the correct names of constants.