MCPcopy Create free account
hub / github.com/astonbitecode/j4rs / static_class

Method static_class

rust/src/api/mod.rs:522–546  ·  view source on GitHub ↗

Retrieves the static class `class_name`.

(&self, class_name: &str)

Source from the content-addressed store, hash-verified

520
521 /// Retrieves the static class `class_name`.
522 pub fn static_class(&self, class_name: &str) -> errors::Result<Instance> {
523 debug(&format!("Retrieving static class {}", class_name));
524 unsafe {
525 // Factory invocation - first argument: create a jstring to pass as argument for the class_name
526 let class_name_jstring: jstring =
527 jni_utils::global_jobject_from_str(class_name, self.jni_env)?;
528
529 // Call the method of the factory that creates a Instance for static calls to methods of class `class_name`.
530 // This returns a Instance that acts like a proxy to the Java world.
531 let java_instance = (opt_to_res(cache::get_jni_call_static_object_method())?)(
532 self.jni_env,
533 cache::get_factory_class()?,
534 cache::get_factory_create_for_static_method()?,
535 class_name_jstring,
536 );
537
538 jni_utils::delete_java_ref(self.jni_env, class_name_jstring);
539
540 // Create and return the Instance.
541 Self::do_return(
542 self.jni_env,
543 Instance::from_jobject_with_global_ref(java_instance)?,
544 )
545 }
546 }
547
548 /// Creates a new Java Array with elements of the class `class_name`.
549 /// The array will have the `InvocationArg`s populated.

Callers 5

java_hello_worldFunction · 0.80
invoke_static_asyncFunction · 0.80
static_class_fieldMethod · 0.80

Calls 8

debugFunction · 0.85
global_jobject_from_strFunction · 0.85
opt_to_resFunction · 0.85
get_factory_classFunction · 0.85
delete_java_refFunction · 0.85
do_returnFunction · 0.85

Tested by 3

java_hello_worldFunction · 0.64