Replace if with switch where feasible

See gh-31916
This commit is contained in:
Yanming Zhou
2023-12-28 15:44:55 +08:00
committed by Stéphane Nicoll
parent ea5ef098cf
commit cfa3aa001f
7 changed files with 85 additions and 157 deletions

View File

@@ -1778,19 +1778,13 @@ class SpelReproTests extends AbstractExpressionTests {
@Override
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
if (beanName.equals("foo")) {
return "custard";
}
else if (beanName.equals("foo.bar")) {
return "trouble";
}
else if (beanName.equals("&foo")) {
return "foo factory";
}
else if (beanName.equals("goo")) {
throw new AccessException("DONT ASK ME ABOUT GOO");
}
return null;
return switch (beanName) {
case "foo" -> "custard";
case "foo.bar" -> "trouble";
case "&foo" -> "foo factory";
case "goo" -> throw new AccessException("DONT ASK ME ABOUT GOO");
default -> null;
};
}
}