Package smile.util

Class AutoScope

java.lang.Object
smile.util.AutoScope
All Implemented Interfaces:
AutoCloseable

public class AutoScope extends Object implements 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 Details

    • AutoScope

      public AutoScope(AutoCloseable... resources)
      Constructors.
      Parameters:
      resources - the resources to be added to this scope.
  • Method Details

    • add

      public <T extends AutoCloseable> T add(T resource)
      Adds resource to this scope.
      Parameters:
      resource - the resource to be added to this scope.
      Returns:
      the resource object.
    • remove

      public void remove(AutoCloseable resource)
      Detaches resources from this scope.
      Parameters:
      resource - the resources to be detached from this scope.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable