Skip to content

Commit

Permalink
refactor: replace simple switch with if-else
Browse files Browse the repository at this point in the history
`switch` statements that have only two arms can be better represented as `if` statements.
  • Loading branch information
deepsource-autofix[bot] authored Nov 15, 2024
1 parent 6c791bf commit 77184db
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions java/source/com/example/autofixables/IffySwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,22 @@ class IffySwitch {
void thing() {
int a = 1;

switch (a) {
case 2:
System.out.println("first 2");
{
System.out.println("second 2");
}
System.out.println("third 2");
break;
default:
System.out.println("default");
if (a == 2) {
System.out.println("first 2");
System.out.println("second 2");
System.out.println("third 2");
} else {
System.out.println("default");
}

switch (a) {
case 2: {
System.out.println("2");
break;
}
default: {
System.out.println("default");
}
if (a == 2) {
System.out.println("2");
} else {
System.out.println("default");
}

switch (a) {
case 2: {
System.out.println("2");
}
default: {
System.out.println("default");
}
if (a == 2) {
System.out.println("2");
}

switch (a) {
Expand Down

0 comments on commit 77184db

Please sign in to comment.