Class AutoCloser<T,​E extends Exception>

    • Constructor Detail

      • AutoCloser

        public AutoCloser​(@NonNull
                          T resource,
                          @NonNull
                          AutoCloser.Closer<T,​E> lambda)
        Adapt the provided resource to be AutoCloseable, using a provided closer lambda.
        Parameters:
        resource - the object to adapt
        lambda - the lambda to use as a callback on close
    • Method Detail

      • autoClose

        @NonNull
        public static <T,​E extends ExceptionAutoCloser<T,​E> autoClose​(@NonNull
                                                                                    T resource,
                                                                                    @NonNull
                                                                                    AutoCloser.Closer<T,​E> lambda)
        Adapt the the provided resource to be AutoCloseable, using a provided closer lambda.
        Type Parameters:
        T - the resource's type
        E - the exception type that can be thrown when closing
        Parameters:
        resource - the object to adapt
        lambda - the lambda to use as a callback on close
        Returns:
        the resource wrapped in an AutoCloseable
      • getResource

        @NonNull
        public T getResource()
        Get the wrapped resource.
        Returns:
        the resource object