update at 2022-02-25 19:54:10 by ehlxr
This commit is contained in:
parent
e54101b14f
commit
d53aa005a6
@ -14,7 +14,7 @@ class HelloWorld {
|
||||
public Long no;
|
||||
private String name;
|
||||
public int age;
|
||||
public List<String> ls;
|
||||
public List<String> list;
|
||||
public Map<String, Long> map;
|
||||
|
||||
private static native String hello(String input);
|
||||
@ -31,7 +31,7 @@ class HelloWorld {
|
||||
|
||||
private static native void asyncComputation(HelloWorld callback);
|
||||
|
||||
private static native List<Map<String, Long>> getField(HelloWorld param);
|
||||
private static native List<Map<String, Object>> getField(HelloWorld param);
|
||||
|
||||
public static void main(String[] args) {
|
||||
String output = HelloWorld.hello("Java");
|
||||
@ -67,7 +67,7 @@ class HelloWorld {
|
||||
hw.setName("Jack");
|
||||
hw.no = 123434555L;
|
||||
hw.age = 30;
|
||||
hw.ls = ls;
|
||||
hw.list = ls;
|
||||
hw.map = map;
|
||||
System.out.println("get return: " + HelloWorld.getField(hw));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_getField(
|
||||
// List field operate
|
||||
let jlist = env
|
||||
.get_list(
|
||||
env.get_field(input, "ls", "Ljava/util/List;")
|
||||
env.get_field(input, "list", "Ljava/util/List;")
|
||||
.unwrap()
|
||||
.l()
|
||||
.unwrap(),
|
||||
@ -98,7 +98,7 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_getField(
|
||||
println!("Hello {}! from Rust..", out_str);
|
||||
|
||||
// new ArrayList operate
|
||||
let jlist = unwrap(
|
||||
let list = unwrap(
|
||||
&env,
|
||||
JList::from_env(
|
||||
&env,
|
||||
@ -107,7 +107,7 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_getField(
|
||||
);
|
||||
|
||||
// new LinkedHashMap operate
|
||||
let jmap = unwrap(
|
||||
let map = unwrap(
|
||||
&env,
|
||||
JMap::from_env(
|
||||
&env,
|
||||
@ -118,27 +118,48 @@ pub extern "system" fn Java_me_ehlxr_HelloWorld_getField(
|
||||
// Map put key value operate
|
||||
unwrap(
|
||||
&env,
|
||||
jmap.put(
|
||||
JObject::from(env.new_string("kd").unwrap()),
|
||||
long_to_jobj(env, 666 as i64),
|
||||
map.put(
|
||||
JObject::from(env.new_string("no").unwrap()),
|
||||
long_to_jobj(env, no),
|
||||
),
|
||||
);
|
||||
unwrap(
|
||||
&env,
|
||||
jmap.put(
|
||||
JObject::from(env.new_string("kk").unwrap()),
|
||||
long_to_jobj(env, 999 as i64),
|
||||
map.put(
|
||||
JObject::from(env.new_string("age").unwrap()),
|
||||
long_to_jobj(env, age as i64),
|
||||
),
|
||||
);
|
||||
let jmap2 = jmap.clone();
|
||||
unwrap(
|
||||
&env,
|
||||
map.put(
|
||||
JObject::from(env.new_string("name").unwrap()),
|
||||
JObject::from(name),
|
||||
),
|
||||
);
|
||||
unwrap(
|
||||
&env,
|
||||
map.put(
|
||||
JObject::from(env.new_string("list").unwrap()),
|
||||
JObject::from(jlist),
|
||||
),
|
||||
);
|
||||
unwrap(
|
||||
&env,
|
||||
map.put(
|
||||
JObject::from(env.new_string("map").unwrap()),
|
||||
JObject::from(jmap),
|
||||
),
|
||||
);
|
||||
let jmap2 = map.clone();
|
||||
|
||||
// List add element operate
|
||||
unwrap(&env, jlist.add(JObject::from(jmap)));
|
||||
unwrap(&env, jlist.add(jmap2));
|
||||
unwrap(&env, list.add(JObject::from(map)));
|
||||
unwrap(&env, list.add(jmap2));
|
||||
|
||||
println!("list size {}", jlist.size().unwrap());
|
||||
println!("list size {}", list.size().unwrap());
|
||||
|
||||
jlist.into_inner()
|
||||
list.into_inner()
|
||||
|
||||
// let output = env
|
||||
// .new_string(format!("Hello {}! from Rust..", out_str))
|
||||
|
Loading…
Reference in New Issue
Block a user