Java: Enum value at compile time?

How do I fetch the value string of an enum at compile time? If I do EnumType.EnumVar.value(), it's resolved at runtime. I want this is to be obtained at compile time so that I can use it in Switch case.

Jon Skeet
people
quotationmark

You don't, basically. If you want to use enums in a switch, you should parse the string value to an enum value, and then switch on that. If the value may not be in the enum, consider creating a Map<String, EnumType> so that you can perform the conversion quickly without the IllegalArgumentException that EnumType.valueOf(String) would throw.

people

See more on this question at Stackoverflow