Class RecycleOnClose<T,E extends java.lang.Exception>
- java.lang.Object
-
- nonapi.io.github.classgraph.recycler.RecycleOnClose<T,E>
-
- Type Parameters:
T- the type to recycleE- the exception type that may be thrown when a recyclable item is acquired.
- All Implemented Interfaces:
java.lang.AutoCloseable
public class RecycleOnClose<T,E extends java.lang.Exception> extends java.lang.Object implements java.lang.AutoCloseableAn AutoCloseable wrapper for a recyclable object instance. Obtained by callingRecycler.acquireRecycleOnClose()in a try-with-resources statement, so that when the try block exits, the acquired instance is recycled.
-
-
Constructor Summary
Constructors Constructor Description RecycleOnClose(Recycler<T,E> recycler, T instance)Acquire or allocate an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Recycle an instance.Tget()Get the object instance.
-
-
-
Constructor Detail
-
RecycleOnClose
RecycleOnClose(Recycler<T,E> recycler, T instance)
Acquire or allocate an instance.- Parameters:
recycler- TheRecycler.instance- An object instance that was obtained by callingRecycler.acquire()on the recycler.- Throws:
java.lang.IllegalArgumentException- IfRecycler.newInstance()returned null.
-
-
Method Detail
-
get
public T get()
Get the object instance.- Returns:
- The object instance.
-
close
public void close()
Recycle an instance. CallsResettable.reset()if the instance implementsResettable.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-