Struct Class

Source
pub struct Class<'env> { /* private fields */ }
Expand description

A type representing a Java Class.

Implementations§

Source§

impl<'env> Class<'env>

Source

pub fn find<'a>( env: &'a JniEnv<'a>, class_name: &str, token: &NoException<'a>, ) -> JavaResult<'a, Class<'a>>

Find an existing Java class by it’s name. The name is a fully qualified class or array type name.

JNI documentation

Source

pub fn define<'a>( env: &'a JniEnv<'a>, bytes: &[u8], token: &NoException<'a>, ) -> JavaResult<'a, Class<'a>>

Define a new Java class from a .class file contents.

JNI documentation

Source

pub fn parent(&self, _token: &NoException<'_>) -> Option<Class<'env>>

Get the parent class of this class. Will return None for the Object class or any interface.

JNI documentation

Source

pub fn is_subtype_of(&self, class: &Class<'_>, _token: &NoException<'_>) -> bool

Check if this class is a subtype of the other class.

In Java a class is a subtype of the other class if that other class is a direct or an indirect parent of this class or an interface this class or any it’s parent is implementing.

JNI documentation

Source§

impl<'env> Class<'env>

Source

pub fn get_class( env: &'env JniEnv<'env>, token: &NoException<'env>, ) -> JavaResult<'env, Class<'env>>

Get the Java class object for Class .

Object::getClass javadoc

Source§

impl<'env> Class<'env>

Source

pub fn clone(&self, token: &NoException<'env>) -> JavaResult<'env, Self>
where Self: Sized,

Clone the Class . This is not a deep clone of the Java object, but a Rust-like clone of the value. Since Java objects are reference counted, this will increment the reference count.

This method has a different signature from the one in the Clone trait because cloning a Java object is only safe when there is no pending exception and because cloning a java object cat throw an exception.

JNI documentation

Source

pub fn to_string( &self, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>

Convert the object to a string.

Object::toString javadoc

Methods from Deref<Target = Object<'env>>§

Source

pub unsafe fn raw_object(&self) -> jobject

Get the raw object pointer.

This function provides low-level access to the Java object and thus is unsafe.

Source

pub fn env(&self) -> &'env JniEnv<'env>

Get the JniEnv this object is bound to.

Source

pub fn class(&self, _token: &NoException<'_>) -> Class<'env>

Get the object’s class.

JNI documentation

Source

pub fn is_same_as(&self, other: &Object<'_>, _token: &NoException<'_>) -> bool

Compare with another Java object by reference.

JNI documentation

Source

pub fn is_instance_of( &self, class: &Class<'_>, _token: &NoException<'_>, ) -> bool

Check if the object is an instance of the class.

JNI documentation

Source

pub fn clone(&self, token: &NoException<'env>) -> JavaResult<'env, Object<'env>>

Clone the Object. This is not a deep clone of the Java object, but a Rust-like clone of the value. Since Java objects are reference counted, this will increment the reference count.

This method has a different signature from the one in the Clone trait because cloning a Java object is only safe when there is no pending exception and because cloning a java object cat throw an exception.

JNI documentation

Source

pub fn to_string( &self, token: &NoException<'env>, ) -> JavaResult<'env, String<'env>>

Convert the object to a string.

Object::toString javadoc

Source

pub fn equals( &self, other: &Object<'_>, token: &NoException<'env>, ) -> JavaResult<'env, bool>

Compare to another Java object.

Object::equals

Trait Implementations§

Source§

impl<'env> Cast<'env, Class<'env>> for Class<'env>

Make Class castable to itself.

Source§

fn cast<'a>(&'a self) -> &'a Class<'env>

Cast the object to itself or one of it’s superclasses. Read more
Source§

impl<'env> Cast<'env, Object<'env>> for Class<'env>

Make Class castable to Object.

Source§

fn cast<'a>(&'a self) -> &'a Object<'env>

Cast the object to itself or one of it’s superclasses. Read more
Source§

impl<'env> Debug for Class<'env>

Source§

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

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

impl<'env> Deref for Class<'env>

Allow Class to be used in place of an Object.

Source§

type Target = Object<'env>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'env> Display for Class<'env>

Allow displaying Class .

Object::toString javadoc

This is mostly a convenience for debugging. Always prefer using to_string to printing the object as is, because the former checks for a pending exception in compile-time rather than the run-time.

Source§

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

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

impl<'env, T> PartialEq<T> for Class<'env>
where T: Cast<'env, Object<'env>>,

Allow comparing Class to Java objects. Java objects are compared by-reference to preserve original Java semantics. To compare objects by value, call the equals method.

Will panic if there is a pending exception in the current thread.

This is mostly a convenience for using assert_eq!() in tests. Always prefer using is_same_as to comparing with ==, because the former checks for a pending exception in compile-time rather than the run-time.

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'env> Eq for Class<'env>

Allow comparing Class to Java objects. Java objects are compared by-reference to preserve original Java semantics. To compare objects by value, call the equals method.

Will panic if there is a pending exception in the current thread.

This is mostly a convenience for using assert_eq!() in tests. Always prefer using is_same_as to comparing with ==, because the former checks for a pending exception in compile-time rather than the run-time.

Source§

impl<'a> JavaType for Class<'a>

Make Class mappable to jobject.

Auto Trait Implementations§

§

impl<'env> Freeze for Class<'env>

§

impl<'env> !RefUnwindSafe for Class<'env>

§

impl<'env> !Send for Class<'env>

§

impl<'env> !Sync for Class<'env>

§

impl<'env> Unpin for Class<'env>

§

impl<'env> !UnwindSafe for Class<'env>

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<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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.