-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Labels
enhancementNew feature or requestNew feature or requestjava 21+recipeRecipe requestedRecipe requested
Description
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 return
s 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);
};
}
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestjava 21+recipeRecipe requestedRecipe requested
Type
Projects
Status
Backlog