File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff 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```
Original file line number Diff line number Diff line change 10401040 " addFinalModifier" ,
10411041 " instanceofPatternMatch" ,
10421042 " lambdaExpression" ,
1043- " switchExpression"
1043+ " switchExpression" ,
1044+ " tryWithResource"
10441045 ]
10451046 },
10461047 "default" : [],
You can’t perform that action at this time.
0 commit comments