mirror of
https://github.com/corda/corda.git
synced 2025-01-09 14:33:30 +00:00
throw IllegalArgumentException from Enum.valueOf if name does not match any value
This commit is contained in:
parent
fb37f48237
commit
864a28f2ce
@ -26,20 +26,21 @@ public abstract class Enum<E extends Enum<E>> implements Comparable<E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
|
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
|
||||||
if (name != null) {
|
if (name == null) throw new NullPointerException();
|
||||||
try {
|
|
||||||
Method method = enumType.getMethod("values");
|
try {
|
||||||
Enum values[] = (Enum[])(method.invoke(null));
|
Method method = enumType.getMethod("values");
|
||||||
for (Enum value : values) {
|
Enum values[] = (Enum[]) (method.invoke(null));
|
||||||
if (name.equals(value.name)) {
|
for (Enum value: values) {
|
||||||
return (T) value;
|
if (name.equals(value.name)) {
|
||||||
}
|
return (T) value;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
throw new IllegalArgumentException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ordinal() {
|
public int ordinal() {
|
||||||
|
Loading…
Reference in New Issue
Block a user