* @exception IllegalArgumentException when there is no value s in
* the enum etype.
*/
- @SuppressWarnings("unchecked")
public static <S extends Enum<S>> S valueOf(Class<S> etype, String s)
{
if (etype == null || s == null)
try
{
+ // XXX We should not use getDeclaredField, because it does
+ // an unnecessary security check.
Field f = etype.getDeclaredField(s);
if (! f.isEnumConstant())
throw new IllegalArgumentException(s);
- return (S) f.get(null);
+ Class.setAccessible(f);
+ @SuppressWarnings("unchecked")
+ S val = (S) f.get(null);
+ return val;
}
catch (NoSuchFieldException exception)
{
k = k.getSuperclass();
return k;
}
+
+ /**
+ * Enumerations can not have finalization methods.
+ *
+ * @since 1.6
+ */
+ protected final void finalize()
+ {
+ }
+
}