Finished example code.
This commit is contained in:
		| @@ -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."); | ||||
|     	} | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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."); | ||||
| 	} | ||||
| } | ||||
| @@ -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."); | ||||
| 	} | ||||
| } | ||||
| @@ -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); | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user