Skip to content

Commit

Permalink
✨ feat: Support Optional for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Sep 1, 2024
1 parent 5ba79af commit 96bede1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rust/src/jni_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,13 @@ unsafe impl Sync for JavaOptional {}

impl JavaOptional {
pub fn new<'local>(env: &mut JNIEnv<'local>) -> Self {
let class = env
.find_class("java/util/Optional")
.expect("Couldn't find class Optional");
let class = if let Ok(class) = env.find_class("java/util/Optional") {
class
} else {
env
.find_class("j$/util/Optional")
.expect("Couldn't find class Optional")
};
let class = env.new_global_ref(class).expect("Couldn't globalize class Optional");
let method_get = env
.get_method_id(&class, "get", "()Ljava/lang/Object;")
Expand Down

0 comments on commit 96bede1

Please sign in to comment.