Skip to content

Commit a016d33

Browse files
committed
Added code comments.
1 parent b0b4ca0 commit a016d33

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* Resource Acquisition Is Initialization pattern was developed
6+
* for exception safe resource management by C++ creator Bjarne
7+
* Stroustrup.
8+
*
9+
* In RAII resource is tied to object lifetime: resource allocation
10+
* is done during object creation while resource deallocation is
11+
* done during object destruction.
12+
*
13+
* In Java RAII is achieved with try-with-resources statement and
14+
* interfaces Closeable and AutoCloseable. The try-with-resources
15+
* statement ensures that each resource is closed at the end of the
16+
* statement. Any object that implements java.lang.AutoCloseable, which
17+
* includes all objects which implement java.io.Closeable, can be used
18+
* as a resource.
19+
*
20+
* In this example, SlidingDoor implements AutoCloseable and
21+
* TreasureChest implements Closeable. Running the example, we can
22+
* observe that both resources are automatically closed.
23+
*
24+
* http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html
25+
*
26+
*/
327
public class App {
428

529
public static void main( String[] args ) throws Exception {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.iluwatar;
22

3+
/**
4+
*
5+
* SlidingDoor resource
6+
*
7+
*/
38
public class SlidingDoor implements AutoCloseable {
49

510
public SlidingDoor() {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import java.io.Closeable;
44
import java.io.IOException;
55

6+
/**
7+
*
8+
* TreasureChest resource
9+
*
10+
*/
611
public class TreasureChest implements Closeable {
712

813
public TreasureChest() {

0 commit comments

Comments
 (0)