Try with resource


Source code

1class TryWithResource {
2
3 void m1() throws Exception {
4 try (AutoCloseable a = newAC()) {
5 a.hashCode();
6 }
7 }
8
9 void m2() {
10 try (AutoCloseable a = newAC()) {
11 a.hashCode();
12 } catch (Exception e) {
13 e.printStackTrace();
14 }
15 }
16
17 private AutoCloseable newAC() {
18 return new java.io.FileReader(
19 java.io.FileDescriptor.err);
20 }
21
22}

Bytecode



Java compiler version: 21
Other examples
Main page