enum has valueOf(string)
method to get enum constant and the same type of method present in java.lang.Enum
class having name valueOf(enumClassName, string)
I found both are giving same output. Then what are other differences. If no difference then why JSL added Enum.valueOf()
?
enum Season {
WINTER,SUMMER
}
class Test {
public static void main(String[] args) {
String season = "WINTER";
//switch (Season.valueOf(colObject)) // following line achieves same thing
switch (Enum.valueOf(Season.class, season)) // any other difference between both approach
{
case WINTER: {
System.out.println("Got it in switch case= VENDOR");
break;
}
default:
System.out.println("Fell thru.");
break;
}
}
}