Skip to content

Commit b0b4ca0

Browse files
committed
Finished example code.
1 parent de7db92 commit b0b4ca0

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

resource-acquisition-is-initialization/src/main/java/com/iluwatar/App.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
public class App {
44

5-
public static void main( String[] args ) {
5+
public static void main( String[] args ) throws Exception {
6+
7+
try (SlidingDoor slidingDoor = new SlidingDoor()) {
8+
System.out.println("Walking in.");
9+
}
10+
11+
try (TreasureChest treasureChest = new TreasureChest()) {
12+
System.out.println("Looting contents.");
13+
}
614
}
715
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.iluwatar;
2+
3+
public class SlidingDoor implements AutoCloseable {
4+
5+
public SlidingDoor() {
6+
System.out.println("Sliding door opens.");
7+
}
8+
9+
@Override
10+
public void close() throws Exception {
11+
System.out.println("Sliding door closes.");
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.iluwatar;
2+
3+
import java.io.Closeable;
4+
import java.io.IOException;
5+
6+
public class TreasureChest implements Closeable {
7+
8+
public TreasureChest() {
9+
System.out.println("Treasure chest opens.");
10+
}
11+
12+
@Override
13+
public void close() throws IOException {
14+
System.out.println("Treasure chest closes.");
15+
}
16+
}

resource-acquisition-is-initialization/src/test/java/com/iluwatar/AppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class AppTest {
66

77
@Test
8-
public void test() {
8+
public void test() throws Exception {
99
String[] args = {};
1010
App.main(args);
1111
}

0 commit comments

Comments
 (0)