I am attempting to find a way to force Java to load/initialize an enumerated type (which is nested within a class that contains a static Map).
This is important to me be
You can just reference something in the enum class. For example:
public class EnumTest {
static final Map map = new HashMap();
enum MyEnum {
FOO, BAR, BAZ;
MyEnum() {
map.put(name(), this);
}
}
static {
// ensure MyEnum is initialized
MyEnum.values();
}
public static void main(String[] argsa) {
System.out.println(map.size());
}
}