Skip to content

Commit 3590b68

Browse files
JessicaJHeergrunber
authored andcommitted
Add setting for try-with-resource clean up
1 parent ae71753 commit 3590b68

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

document/_java.learnMoreAboutCleanUps.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,28 @@ int i = switch(j) {
273273
case 2 -> 4;
274274
default -> 0;
275275
};
276+
```
277+
278+
### `tryWithResource`
279+
280+
Simplifies the finally block to use the `try-with-resource` statement.
281+
282+
For example:
283+
284+
```java
285+
final FileInputStream inputStream = new FileInputStream("out.txt");
286+
try {
287+
System.out.println(inputStream.read());
288+
} finally {
289+
inputStream.close();
290+
}
291+
```
292+
293+
becomes:
294+
295+
```java
296+
final FileInputStream inputStream = new FileInputStream("out.txt");
297+
try (inputStream) {
298+
System.out.println(inputStream.read());
299+
}
276300
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@
10401040
"addFinalModifier",
10411041
"instanceofPatternMatch",
10421042
"lambdaExpression",
1043-
"switchExpression"
1043+
"switchExpression",
1044+
"tryWithResource"
10441045
]
10451046
},
10461047
"default": [],

0 commit comments

Comments
 (0)