Java enum reverse look-up best practice
I saw it suggested on a blog that the following was a reasonable way to do a "reverse-lookup" using the getCode(int) in a Java enum: public enum Status { WAITING(0), READY(1), SKIPPED(-1), COMPLETED(5); private static final Map<Integer,Status> lookup = new HashMap<Integer,Status>(); static { for(Status s : EnumSet.allOf(Status.class)) lookup.put(s.getCode(), s); } private int code; private Status(int code) { this.code = code; } public int getCode() { return code; } public static Status get(int code) { return lookup.get(code); } } To me, the static map and the static initializer both look like