Finished example code.

This commit is contained in:
Ilkka Seppala 2015-05-16 22:03:26 +03:00
parent de7db92f59
commit b0b4ca09f8
4 changed files with 39 additions and 2 deletions

View File

@ -2,6 +2,14 @@ package com.iluwatar;
public class App {
public static void main( String[] args ) {
public static void main( String[] args ) throws Exception {
try (SlidingDoor slidingDoor = new SlidingDoor()) {
System.out.println("Walking in.");
}
try (TreasureChest treasureChest = new TreasureChest()) {
System.out.println("Looting contents.");
}
}
}

View File

@ -0,0 +1,13 @@
package com.iluwatar;
public class SlidingDoor implements AutoCloseable {
public SlidingDoor() {
System.out.println("Sliding door opens.");
}
@Override
public void close() throws Exception {
System.out.println("Sliding door closes.");
}
}

View File

@ -0,0 +1,16 @@
package com.iluwatar;
import java.io.Closeable;
import java.io.IOException;
public class TreasureChest implements Closeable {
public TreasureChest() {
System.out.println("Treasure chest opens.");
}
@Override
public void close() throws IOException {
System.out.println("Treasure chest closes.");
}
}

View File

@ -5,7 +5,7 @@ import org.junit.Test;
public class AppTest {
@Test
public void test() {
public void test() throws Exception {
String[] args = {};
App.main(args);
}