Class NativeHandleGuard

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class NativeHandleGuard
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Provides access to a Rust object handle while keeping the Java wrapper alive. Intended for use with try-with-resources syntax. NativeHandleGuard prevents the Java wrapper from being finalized, which would destroy the Rust object, while the handle is in use. To use it, the Java wrapper type should conform to the NativeHandleGuard.Owner interface. Note that it is not necessary to use NativeHandleGuard in the implementation of finalize itself. The point of NativeHandleGuard is to delay finalization while the Rust object is being used; once finalization has begun, there can be no other uses of the Rust object from Java.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  NativeHandleGuard.Owner  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      long nativeHandle()
      Returns the native handle owned by the Java object, or 0 if the owner is null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • nativeHandle

        public long nativeHandle()
        Returns the native handle owned by the Java object, or 0 if the owner is null.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable