Files
Mikhail Pyltsinandintellij-monorepo-bot 852b99222d [java-inspections] IDEA-335728 Duplicate branches can't be merge in switch
- added condition for available feature

GitOrigin-RevId: a8ae325cdd2843a932bf03fc535505a41865a9fb
2023-10-20 14:12:37 +00:00

65 lines
1.8 KiB
Java

// "Fix all 'Duplicate branches in 'switch'' problems in file" "true"
class C {
void foo(Object o) {
switch (o) {
case Integer _, String _ -> System.out.println(1); //can be merged
default -> System.out.println(2);
}
}
void foo2(Object o) {
switch (o) {
case Integer _ when o.hashCode() == 1 -> System.out.println(1);
case String _ -> System.out.println(1);
default -> System.out.println(2);
}
}
void foo3(Object o) {
switch (o) {
case Integer _, String _ when o.hashCode() == 1 -> System.out.println(1); //can be merged
default -> System.out.println(2);
}
}
void foo4(Object o) {
switch (o) {
case Integer _, String _ when o.hashCode() == 1 -> System.out.println(1); //can be merged
case Number s -> System.out.println(3);
default -> System.out.println(2);
}
}
void foo5(Object o) {
switch (o) {
case Integer _ when o.hashCode() == 1 -> System.out.println(1);
case Number s -> System.out.println(3);
case String _ when o.hashCode() == 2 -> System.out.println(1);
default -> System.out.println(2);
}
}
void foo6(Object o) {
switch (o) {
case Integer _ when o.hashCode() == 1 -> System.out.println(1);
case Number s -> System.out.println(3);
case String _ -> System.out.println(1);
default -> System.out.println(2);
}
}
void foo7(Object o) {
switch (o) {
case Integer _, String _ -> System.out.println(1); //can be merged
default -> System.out.println(2);
}
}
void foo8(Object o) {
switch (o) {
case Integer _, CharSequence _ when o.hashCode() == 1 -> System.out.println(1); //can be merged
case Number s -> System.out.println(3);
default -> System.out.println(2);
}
}
}