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) {
273
273
case 2 - > 4 ;
274
274
default - > 0 ;
275
275
};
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
+ }
276
300
```
Original file line number Diff line number Diff line change 1040
1040
" addFinalModifier" ,
1041
1041
" instanceofPatternMatch" ,
1042
1042
" lambdaExpression" ,
1043
- " switchExpression"
1043
+ " switchExpression" ,
1044
+ " tryWithResource"
1044
1045
]
1045
1046
},
1046
1047
"default" : [],
You can’t perform that action at this time.
0 commit comments