Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions document/_java.learnMoreAboutCleanUps.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,44 @@ switch (r) {
case R _ -> {}
}
```

### `useSwitchForInstanceofPattern`

Convert if/else chains to pattern matching switch statements.

For example:

```java
int i, j;
double d;
boolean b;
if (x instanceof Integer xint) {
i = xint.intValue();
} else if (x instanceof Double xdouble) {
d = xdouble.doubleValue();
} else if (x instanceof Boolean xboolean) {
b = xboolean.booleanValue();
} else {
i = 0;
d = 0.0D;
b = false;
}
```

becomes:

```java
int i, j;
double d;
boolean b;
switch (x) {
case Integer xint -> i = xint.intValue();
case Double xdouble -> d = xdouble.doubleValue();
case Boolean xboolean -> b = xboolean.booleanValue();
case null, default -> {
i = 0;
d = 0.0D;
b = false;
}
}
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,8 @@
"tryWithResource",
"renameFileToType",
"organizeImports",
"renameUnusedLocalVariables"
"renameUnusedLocalVariables",
"useSwitchForInstanceofPattern"
]
},
"default": [
Expand Down