Interface Disposable
-
- All Known Implementing Classes:
CaptureInputStream
,CaptureOutputStream
,FixedLengthInputStream
,InputStreamDecorator
,OutputStreamDecorator
,ProgressOutputStream
,TempFileInputStream
,TempOutputStream
public interface Disposable
Indicates that an object supports explicit uninitialization at the end of its life.When a disposable object will no longer be used, its
dispose()
method should be called, and the object should not be used further. Thedispose()
can be called multiple times without danger. It is not defined here what component calls thedispose()
method. Furthermore, the object's behavior if used further is implementation and context-specific.The
dispose()
method is considered to be a last-chance opportunity to release resources; it therefore should allow no exceptions to escape. Disposing an object is considered to be an operation more final thanclose()
(although aclose()
method may calldispose()
), but less final thanfinalize()
(althoughfinalize()
may and should calldispose()
). One of its uses is in the following pattern:Disposable myDisposable=createDisposable(); try { ... } finally { myDisposable.dispose(); }
Implementing classes should normally call
dispose()
fromfinalize
using the following pattern:@Override protected void finalize() throws Throwable { try { dispose(); } finally { super.finalize(); } }
Such a pattern prevents the
try{} finally{ object.close() }
problem in which closing the object attempts to retry an operation which caused an exception in the first place.- Author:
- Garret Wilson
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
dispose()
Uninitializes the object.
-