Package no.digipost.util
Class AutoClosed<T>
- java.lang.Object
-
- no.digipost.util.AutoClosed<T>
-
- Type Parameters:
T
- The type of the arbitrary object which will have an operation invoked on exiting from a try-with-resources block.
- All Implemented Interfaces:
AutoCloseable
public final class AutoClosed<T> extends Object implements AutoCloseable
An adapter to enable any arbitrary object to be managed by the try-with-resources facility of Java >= 7, i.e. it will have a closing operation invoked when exiting thetry
-block.
-
-
Constructor Summary
Constructors Constructor Description AutoClosed(T managedObject, Consumer<? super T> closeOperation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
T
object()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Method Detail
-
object
public T object()
- Returns:
- the object managed by try-with-resources.
-
close
public void close() throws X extends Exception
- Throws:
X extends Exception
- See Also:
AutoCloseable.close()
-
-