I have the feeling that your design is getting too complicated.
With transfers
If you do not require class inheritance, you can work with enumerations directly, as with top-level classes.
public interface Animal {} public enum Dog implements Animal { HUSKY("Husky"), LAB("Labrador"); private final String name; Dog(String name) { this.name = name; } public String getName() { return name; } }
Enums can declare fields, methods, and implement interfaces like any other Java class. Their only limitation is that their direct superclass is always java.lang.Enum , and they cannot be extended.
However, each enumerator constant can have its own set of unique data passed to its constructor. It is even possible that each of the constants can override the general method of this enumeration with its unique implementation.
A good tutorial explaining more about the full power of listings: http://javarevisited.blogspot.cz/2011/08/enum-in-java-example-tutorial.html
No transfers
If you need the actual inheritance of the class to share some common methods (for example, from the Animal superclass), I still refuse the approach to the map and rather try something more OOP-oriented:
public class Animal { } public abstract class Dog extends Animal { public abstract String getName(); public static class Husky extends Dog { @Override public String getName() { return "husky"; } } public static class Lab extends Dog { @Override public String getName() { return "labrador"; } } }
Natix source share