Package smile.util
Class AutoScope
java.lang.Object
smile.util.AutoScope
- All Implemented Interfaces:
AutoCloseable
AutoScope allows for predictable, deterministic resource deallocation.
AutoScope can be closed explicitly or be best used with try-with-resources
Statement. Closing an AutoScope will cause all the cleanup actions
associated with that scope to be called.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T extends AutoCloseable>
Tadd
(T resource) Adds resource to this scope.void
close()
void
remove
(AutoCloseable resource) Detaches resources from this scope.
-
Constructor Details
-
AutoScope
Constructors.- Parameters:
resources
- the resources to be added to this scope.
-
-
Method Details
-
add
Adds resource to this scope.- Parameters:
resource
- the resource to be added to this scope.- Returns:
- the resource object.
-
remove
Detaches resources from this scope.- Parameters:
resource
- the resources to be detached from this scope.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-