可能可以实现通用静态
lookup方法。
像这样
public class LookupUtil { public static <E extends Enum<E>> E lookup(Class<E> e, String id) { try { E result = Enum.valueOf(e, id); } catch (IllegalArgumentException e) { // log error or something here throw new RuntimeException("Invalid value for enum " + e.getSimpleName() + ": " + id); } return result; }}那么你就可以
public enum MyEnum { static public MyEnum lookup(String id) { return LookupUtil.lookup(MyEnum.class, id); }}或显式调用实用程序类查找方法。



