@Override public <T> T get(Enum key, Class<T> resultClass, T defaultValue) { if (defaultValue == null) { try { String def = key.getDeclaringClass().getField(key.name()).getAnnotation(Default.class).value(); if (resultClass == String.class) return (T) def; return resultClass.getConstructor(String.class).newInstance(def); } catch (Exception e) { throw new RegisteredExceptionWrapper(e); } } return defaultValue; }
public <T extends Enum<T>> T getSelected(Class<T> clazz) { Default d = clazz.getAnnotation(Default.class); return d != null ? Enum.<T>valueOf(clazz, d.value()) : clazz.getAnnotation(FirstIsDefault.class) != null ? clazz.getEnumConstants()[0] : null; }