In my application, I receive a response that has hard-coded values it can be. I have created an enum with those responses as so:
enum ResponseCode {
APPROVED("AP"),
REJECTED("RJ"),
...;
private final String code;
private ResponseCode(String code) {
this.code = code;
}
}
I would handle a response differently depending on which code I receive. I thought of using a switch-case to solve this problem.
String response = functionThatReturnsString(); // Could be "AP" or "RJ" etc.
switch(response) {
case ResponseCode.APPROVED:
// Response handling here
break;
...
}
However, I get the error Type mismatch: cannot convert from ResponseCode to String
Is there a way to get around this? Or is there a better way to do this?