代码片断:无异常地把字符串解析成枚举 Leave a Comment / Java / May 12, 2014 May 12, 2014 public static MyEnum safelyParse(String str) { if (str == null) { return null; } MyEnum[] values = MyEnum.values(); for (MyEnum value : values) { if (value.name().equals(str)) { return value; } } return null; }