I am writing an interpreter that parses an array of String and assigns each word in that file a numeric value.
What I want to accomplish, is this:
If the word is not found in the enum, call an external method parse() for that particular element of the array.
My code looks similar to this:
private enum Codes {keyword0, keyword1};
switch Codes.valueOf(stringArray[0])
{
case keyword0:
{
value = 0;
break;
}
case keyword1:
{
value = 1;
break;
}
default:
{
value = parse(StringArray[0]);
break;
}
}
Unfortunately, when this finds something that does not equal “keyword0” or “keyword1” in the input, I get
No enum const class
Thanks in advance!
When there’s no corresponding enum value, there will always be an
IllegalArgumentExceptionthrown. Just catch this, and you’re good.