update at 2022-02-25 10:30:10 by ehlxr

This commit is contained in:
ehlxr 2022-02-25 10:30:10 +08:00
parent 7fa307f3a6
commit 7ffd8ac5f2
2 changed files with 26 additions and 18 deletions

View File

@ -2,6 +2,7 @@ package me.ehlxr;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
class HelloWorld {
static {
@ -56,11 +57,18 @@ class HelloWorld {
ls.add("ls1");
ls.add("ls2");
ls.add("ls3");
Map<String, Long> map = new HashMap<>();
map.put("k1", 1L);
map.put("k2", 2L);
map.put("k3", 3L);
HelloWorld hw = new HelloWorld();
hw.setName("Jack");
hw.no = 123434555L;
hw.age = 30;
hw.ls = ls;
hw.map = map;
System.out.println(HelloWorld.getFiled(hw));
}

View File

@ -1,7 +1,6 @@
use jni::objects::{GlobalRef, JClass, JList, JObject, JString, JValue};
use jni::objects::{GlobalRef, JClass, JObject, JString, JValue};
use jni::sys::{jbyteArray, jint, jlong, jstring};
use jni::JNIEnv;
use std::slice::SliceIndex;
use std::{sync::mpsc, thread, time::Duration};
#[no_mangle]
@ -16,14 +15,14 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_getFiled(
.l()
.unwrap();
let jmap = env.get_map(map).unwrap();
// jmp.get(slice)
jmap.iter().unwrap().into_iter().for_each(|jmap_iter| {
let key: JString = jmap_iter.0.into();
let value: JString = jmap_iter.1.into();
let value = jmap_iter.1;
println!(
"get map key: {}, value: {}",
String::from(env.get_string(key).unwrap()),
String::from(env.get_string(value).unwrap())
long_value(env, value)
);
});
@ -60,19 +59,13 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_getFiled(
// let no = env.get_field(input, "no", "J").unwrap().j().unwrap();
// println!("get no field: {}", no);
let no = env
.call_method(
env.get_field(input, "no", "Ljava/lang/Long;")
.unwrap()
.l()
.unwrap(),
"longValue",
"()J",
&[],
)
.unwrap()
.j()
.unwrap();
let no = long_value(
env,
env.get_field(input, "no", "Ljava/lang/Long;")
.unwrap()
.l()
.unwrap(),
);
println!("get no field: {}", no);
let out_str = if let JValue::Object(result) = env
@ -221,6 +214,13 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_asyncComputation(
rx.recv().unwrap();
}
fn long_value(env: JNIEnv, jobj: JObject) -> i64 {
env.call_method(jobj, "longValue", "()J", &[])
.unwrap()
.j()
.unwrap()
}
#[cfg(test)]
mod tests {
#[test]