Open
Description
What problem are you trying to solve?
switch(null) is not supported before Java 18. Adding it to this recipe when using java 18 might be a useful extension.
Describe the solution you'd like
"""
import java.util.Objects;
class Test {
public String determineSomething(String a, String b) {
return Objects.equals(a, "a") ? "a" : Objects.equals(a, "b") ? b : "nope";
}
}
""",
"""
class Test {
public String determineSomething(String a, String b) {
return switch (a) {
case "a" -> "a";
case "b" -> b;
case null -> "nope";
default -> "nope";
};
}
}
"""
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Backlog