代码片断:无异常地把字符串解析成枚举


	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;

	}

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.