I have to validate a CSV file with a bunch of columns. Some of them need to map to various enum types. I know how to validate string value against a specific enum type, but I would like to have a generic validation method where I would pass in string value and enum type and get validation result. So far I have this:
private boolean valitateSomeSpecificEnum(String value) {
try {
SomeSpecificEnum.valueOf(value);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
Is it possible to have something like:
private boolean valitateAgainstTheEnum(String value, Enum<?> theEnum) {
try {
theEnum.valueOf(value);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
and then call it like so
valitateTheEnum("foo", SomeSpecificEnum.class);
is this even possible?
1