Currently the IfElseIfConstructToSwitch recipe does not convert to a switch if any of the parts would return.
However, if all branches would return, we could convert it to and it could be a potential candidate. Only the intermediate phase of having returns in the case is not valid, hence would not be picked up by:
static String formatter(Object obj) {
if (obj instanceof String s) {
return s;
} else if (obj instanceof Long l) {
return String.valueOf(l);
} else {
throw new IllegalStateException("Unexpected value: " + obj);
}
}
could become
static String formatter(Object obj) {
return switch (obj) {
case String s -> s;
case Long l -> String.valueOf(l);
default -> throw new IllegalStateException("Unexpected value: " + obj);
};
}
Currently the
IfElseIfConstructToSwitchrecipe does not convert to a switch if any of the parts would return.However, if all branches would return, we could convert it to and it could be a potential candidate. Only the intermediate phase of having
returns in the case is not valid, hence would not be picked up by:could become