Skip to main content

JObject

Struct JObject 

Source
pub struct JObject<'local> { /* private fields */ }
Expand description

A java.lang.Object reference, tied to a JNI local reference frame.

This is a #[repr(transparent)] wrapper around a jobject JNI reference.

Since it is #[repr(transparent)], it can be used to capture references passed to native methods while also associating them with a local reference frame lifetime for the method call.

§Casting

Most other types in the objects module implement Into<JObject> or AsRef<JObject> to allow easy upcasting to JObject.

For downcasting (i.e converting to a more specific type), with runtime checks, use one of these APIs:

or look for a cast_local API like JString::cast_local.

§Local Reference Frame Lifetime

The lifetime 'local represents the local reference frame that this reference belongs to. See the Env documentation for more information about local reference frames.

The lifetime may be 'static if the reference has a Global or Weak wrapper that indicates that the reference is global or weak (i.e it does not belong to a local reference frame).

Note that an owned JObject is always a local reference and will never have the 'static lifetime. Global does implement AsRef<JObject<’static>>, but this only yields a borrowed &JObject<'static>, never an owned JObject<'static>.

Local references belong to a single thread and are not safe to share across threads. This type implements Send and Sync if and only if the lifetime 'local is 'static.

Implementations§

Source§

impl JObject<'_>

Source

pub unsafe fn from_raw<'local>( _env: &Env<'local>, raw: jobject, ) -> JObject<'local>

Creates a JObject that wraps the given raw jobject

§Safety
  • raw must be a valid raw JNI local reference (or null).
  • There must not be any other owning Reference wrapper for the same reference.
  • The local reference must belong to the current thread and not outlive the JNI stack frame associated with the Env 'local lifetime.
Source

pub const fn null() -> JObject<'static>

Creates a new null reference.

Null references are always valid and do not belong to a local reference frame. Therefore, the returned JObject always has the 'static lifetime.

Source

pub const fn as_raw(&self) -> jobject

Returns the raw JNI pointer.

Source

pub const fn into_raw(self) -> jobject

Unwrap to the internal jni type.

Trait Implementations§

Source§

impl<'local> AsMut<JObject<'local>> for JObject<'local>

Source§

fn as_mut(&mut self) -> &mut JObject<'local>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JArrayIndexOutOfBoundsException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JArrayStoreException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JByteBuffer<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JCharSequence<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JClass<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JClassCircularityError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JClassFormatError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JClassLoader<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JClassNotFoundException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JCollection<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JExceptionInInitializerError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JIllegalArgumentException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JIllegalMonitorStateException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JInstantiationException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JIterator<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JLinkageError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JList<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JMap<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JMapEntry<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JNoClassDefFoundError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JNoSuchFieldError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JNoSuchMethodError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JNumberFormatException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JObject<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local, E: Reference> AsRef<JObject<'local>> for JObjectArray<'local, E>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JOutOfMemoryError<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local, T: TypeArray> AsRef<JObject<'local>> for JPrimitiveArray<'local, T>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JRuntimeException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JSecurityException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JSet<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JStackTraceElement<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JString<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JStringIndexOutOfBoundsException<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JThread<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JThrowable<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> Debug for JObject<'local>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JObject<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for JObject<'_>

Source§

type Target = *mut _jobject

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'local> From<JArrayIndexOutOfBoundsException<'local>> for JObject<'local>

Source§

fn from(other: JArrayIndexOutOfBoundsException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JArrayStoreException<'local>> for JObject<'local>

Source§

fn from(other: JArrayStoreException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JByteBuffer<'local>> for JObject<'local>

Source§

fn from(other: JByteBuffer<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JCharSequence<'local>> for JObject<'local>

Source§

fn from(other: JCharSequence<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JClass<'local>> for JObject<'local>

Source§

fn from(other: JClass<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JClassCircularityError<'local>> for JObject<'local>

Source§

fn from(other: JClassCircularityError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JClassFormatError<'local>> for JObject<'local>

Source§

fn from(other: JClassFormatError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JClassLoader<'local>> for JObject<'local>

Source§

fn from(other: JClassLoader<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JClassNotFoundException<'local>> for JObject<'local>

Source§

fn from(other: JClassNotFoundException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JCollection<'local>> for JObject<'local>

Source§

fn from(other: JCollection<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JExceptionInInitializerError<'local>> for JObject<'local>

Source§

fn from(other: JExceptionInInitializerError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JIllegalArgumentException<'local>> for JObject<'local>

Source§

fn from(other: JIllegalArgumentException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JIllegalMonitorStateException<'local>> for JObject<'local>

Source§

fn from(other: JIllegalMonitorStateException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JInstantiationException<'local>> for JObject<'local>

Source§

fn from(other: JInstantiationException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JIterator<'local>> for JObject<'local>

Source§

fn from(other: JIterator<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JLinkageError<'local>> for JObject<'local>

Source§

fn from(other: JLinkageError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JList<'local>> for JObject<'local>

Source§

fn from(other: JList<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JMap<'local>> for JObject<'local>

Source§

fn from(other: JMap<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JMapEntry<'local>> for JObject<'local>

Source§

fn from(other: JMapEntry<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JNoClassDefFoundError<'local>> for JObject<'local>

Source§

fn from(other: JNoClassDefFoundError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JNoSuchFieldError<'local>> for JObject<'local>

Source§

fn from(other: JNoSuchFieldError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JNoSuchMethodError<'local>> for JObject<'local>

Source§

fn from(other: JNoSuchMethodError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JNumberFormatException<'local>> for JObject<'local>

Source§

fn from(other: JNumberFormatException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local, E: Reference> From<JObjectArray<'local, E>> for JObject<'local>

Source§

fn from(other: JObjectArray<'local, E>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JOutOfMemoryError<'local>> for JObject<'local>

Source§

fn from(other: JOutOfMemoryError<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local, T: TypeArray> From<JPrimitiveArray<'local, T>> for JObject<'local>

Source§

fn from(other: JPrimitiveArray<'local, T>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JRuntimeException<'local>> for JObject<'local>

Source§

fn from(other: JRuntimeException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JSecurityException<'local>> for JObject<'local>

Source§

fn from(other: JSecurityException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JSet<'local>> for JObject<'local>

Source§

fn from(other: JSet<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JStackTraceElement<'local>> for JObject<'local>

Source§

fn from(other: JStackTraceElement<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JString<'local>> for JObject<'local>

Source§

fn from(other: JString<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JStringIndexOutOfBoundsException<'local>> for JObject<'local>

Source§

fn from(other: JStringIndexOutOfBoundsException<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JThread<'local>> for JObject<'local>

Source§

fn from(other: JThread<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JThrowable<'local>> for JObject<'local>

Source§

fn from(other: JThrowable<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl Reference for JObject<'_>

Source§

type Kind<'env> = JObject<'env>

The generic associated Self::Kind type corresponds to the underlying class type (such as JObject or JString), parameterized by the lifetime that indicates whether the type holds a global reference ('static) or a local reference that’s tied to a JNI stack frame. Read more
Source§

type GlobalKind = JObject<'static>

The associated GlobalKind type should be equivalent to Kind<'static>, with the additional bound that ensures the type is Send + Sync Read more
Source§

fn as_raw(&self) -> jobject

Returns the underlying, raw crate::sys::jobject reference.
Source§

fn class_name() -> Cow<'static, JNIStr>

The fully qualified class name of the Java class represented by this reference. Read more
Source§

fn lookup_class<'caller>( env: &Env<'_>, _loader_context: &LoaderContext<'_, '_>, ) -> Result<impl Deref<Target = Global<JClass<'static>>> + 'caller>

Looks up a global reference to the JClass associated with this reference. Read more
Source§

unsafe fn kind_from_raw<'env>(local_ref: jobject) -> Self::Kind<'env>

Returns a new reference type based on Self::Kind for the given reference that is tied to the specified lifetime. Read more
Source§

unsafe fn global_kind_from_raw(global_ref: jobject) -> Self::GlobalKind

Returns a ('static) reference type based on Self::GlobalKind for the given global_ref. Read more
Source§

fn is_null(&self) -> bool

Returns true if this is a null object reference
Source§

fn null<'any>() -> Self::Kind<'any>

Returns null reference based on Self::Kind
Source§

impl<'local> TryFrom<JValueOwned<'local>> for JObject<'local>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: JValueOwned<'local>) -> Result<Self>

Performs the conversion.
Source§

impl Send for JObject<'static>

Source§

impl Sync for JObject<'static>

Auto Trait Implementations§

§

impl<'local> Freeze for JObject<'local>

§

impl<'local> RefUnwindSafe for JObject<'local>

§

impl<'local> Unpin for JObject<'local>

§

impl<'local> UnsafeUnpin for JObject<'local>

§

impl<'local> UnwindSafe for JObject<'local>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'local, T> Desc<'local, T> for T
where T: AsRef<T>,

Source§

type Output = T

The type that this Desc returns.
Source§

fn lookup(self, _: &mut Env<'local>) -> Result<T, Error>

Look up the concrete type from the JVM. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'local, T> IntoAuto<'local> for T
where T: Into<JObject<'local>>,

Source§

fn auto(self) -> Auto<'local, Self>

Wraps the local reference type into an auto-delete Auto that will automatically delete the local reference when it is dropped
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.