suppose you got an enum defined like this:
enum ServerErrorCodes {
OK(100), NotFound(404);
private final int id;
ServerErrorCodes(int id) {
this.id = id;
}
}
Then suppose you get back an error code from a server as an integer, how do I convert that integer to enum ServerErrorCodes. I would like to write something like:
int result = getServerService("document");// dummy code just for this example
ServerErrorCodes serverResult = result; // this does not work. What magic is required, though?
switch (serverResult) {
case OK:
return true;
case NotFound:
return false;
}
Does anyone here know how to do it?
Regards,
Johan

New Topic/Question
Reply
MultiQuote









|