Class NativeHandle

  • All Implemented Interfaces:
    AutoCloseable

    public final class NativeHandle
    extends Object
    implements AutoCloseable
    An implementation-specific handle to the native object. Once closed, can no longer be accessed.
    • Field Detail

      • INVALID_NATIVE_HANDLE

        public static final long INVALID_NATIVE_HANDLE
        A reserved value for an invalid native handle, equal to nullptr in C++.
        See Also:
        Constant Field Values
    • Constructor Detail

      • NativeHandle

        public NativeHandle​(long nativeHandle)
        Creates new native handle. Validates it's state not allowing to create nullptr handle.
        Throws:
        IllegalStateException - if this native handle is invalid (nullptr)
    • Method Detail

      • get

        public long get()
        Returns a native implementation-specific handle if it may be safely used to access the native object.

        The returned value shall only be passed as an argument to native methods.

        Warning: do not cache the return value, as you won't be able to catch use-after-free.

        Throws:
        IllegalStateException - if this native handle is invalid (closed or nullptr)