So I have a java class with multiple Enums
public class Enumerations {
public enum Days {
Monday("MON")
Tuesday("Tue")
string value;
private Days(String value){
this.value = value
}
public string getValue(){
return this.value;
}
}
public enum Months{
January("JAN")
APRIL("APR")
string value;
private Months(String value){
this.value = value
}
public string getValue(){
return this.value;
}
}
}
And now I have another class in which I want to access the enum class via a string as i cannot instantiate the enum directly as i am unaware of the enum that is to be used and access enum values from a variable string(unaware of this as well).
class EnumParser{
public static void main(String args[]){
String enum = "Days"; //Will get this value from external source so its variable(Can be months or days)
String value = "Monday" //This is going to variable as well with value unknown.
}
}
So how do i get output as "MON" here using string variables
Enumerations.{{Days}}.{{Monday}}.getValue();
edited the question for a clearer view, both Days ans Monday are variables.