We have a REST API where clients can supply parameters representing values defined on the server in Java Enums.
So we can provide a descriptive error, we add this
Why do we have to write that 5 line code ?
public class EnumTest { public enum MyEnum { A, B, C, D; } @Test public void test() throws Exception { MyEnum.valueOf("A"); //gives you A //this throws ILlegalargument without having to do any lookup MyEnum.valueOf("RADD"); } }