Brian

9%
Flag icon
If clients surround all Room instantiations in try-with-resource blocks, automatic cleaning will never be required. This well-behaved client demonstrates that behavior: Click here to view code image public class Adult {     public static void main(String[] args) {         try (Room myRoom = new Room(7)) {             System.out.println("Goodbye");         }     } }
Brian
Try with resource is new to me. It invokes the close method because the Room class implements AutoClosable? And cleaner, by virtue of being registered, will get invoked at gc (maybe)?
Corey
· Flag
Corey
Yes. Try with resources is syntax sugar for:
Room myRoom = new Room();
try {
doStuff()....
} finally {
room.close();
}

Thats all there is to it.
Effective Java
Rate this book
Clear rating
Open Preview