Class ThrowingAutoClosed<T,X extends Exception>

java.lang.Object
no.digipost.util.ThrowingAutoClosed<T,X>
Type Parameters:
T - The type of the arbitrary object which will have an operation invoked on exiting from a try-with-resources block.
X - The type of exception which may be throwed by the closeOperation
All Implemented Interfaces:
AutoCloseable

public final class ThrowingAutoClosed<T,X extends Exception> 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 the try-block.
  • Constructor Details

    • ThrowingAutoClosed

      public ThrowingAutoClosed(T managedObject, ThrowingConsumer<? super T,X> closeOperation)
  • Method Details

    • object

      public T object()
      Returns:
      the object managed by try-with-resources.
    • close

      public void close() throws X
      Throws:
      X extends Exception
      See Also: