Sunday, 3 July 2016

java - Convert String to Enum?












I have a method that uses an enum:



mymethod(AnotherClass.MyEnum.PassedEnum);


And I want to nest this within a class that receives a String which becomes MyEnum:



public static void method(String toPass){

mymethod(AnotherClass.toPass.PassedEnum);


}


The passed variable has to be a String but I need to convert it to a Enum to pass to AnotherClass?



TIA


Answer



Use AnotherClass.MyEnum.valueOf(toPass)


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...