update at 2022-02-24 11:03:22 by ehlxr
This commit is contained in:
@@ -1,25 +1,35 @@
|
||||
package me.ehlxr;
|
||||
|
||||
class HelloWorld {
|
||||
private static native String hello(String input);
|
||||
private static native byte[] helloByte(byte[] input);
|
||||
private static native void factAndCallMeBack(int n, HelloWorld callback);
|
||||
private static native long counterNew(HelloWorld callback);
|
||||
private static native void counterIncrement(long counter_ptr);
|
||||
private static native void counterDestroy(long counter_ptr);
|
||||
private static native void asyncComputation(HelloWorld callback);
|
||||
|
||||
private static native String fetchNameStr(HelloWorld param);
|
||||
|
||||
static {
|
||||
// Linux: export LD_LIBRARY_PATH=/Users/ehlxr/Desktop/jni_rs/mylib/target/debug
|
||||
// Mac: export JAVA_LIBRARY_PATH=/Users/ehlxr/Desktop/jni_rs/mylib/target/debug
|
||||
System.loadLibrary("mylib");
|
||||
}
|
||||
|
||||
public long no;
|
||||
private String name;
|
||||
public int age;
|
||||
|
||||
private static native String hello(String input);
|
||||
|
||||
private static native byte[] helloByte(byte[] input);
|
||||
|
||||
private static native void factAndCallMeBack(int n, HelloWorld callback);
|
||||
|
||||
private static native long counterNew(HelloWorld callback);
|
||||
|
||||
private static native void counterIncrement(long counter_ptr);
|
||||
|
||||
private static native void counterDestroy(long counter_ptr);
|
||||
|
||||
private static native void asyncComputation(HelloWorld callback);
|
||||
|
||||
private static native String getFiled(HelloWorld param);
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String output = HelloWorld.hello("Java");
|
||||
// System.out.println(output);
|
||||
String output = HelloWorld.hello("Java");
|
||||
System.out.println(output);
|
||||
|
||||
// byte[] outputByte = HelloWorld.helloByte("byte".getBytes());
|
||||
// System.out.println(outputByte);
|
||||
@@ -29,7 +39,7 @@ class HelloWorld {
|
||||
// long counter_ptr = counterNew(new HelloWorld());
|
||||
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// counterIncrement(counter_ptr);
|
||||
// counterIncrement(counter_ptr);
|
||||
// }
|
||||
|
||||
// counterDestroy(counter_ptr);
|
||||
@@ -37,28 +47,27 @@ class HelloWorld {
|
||||
// System.out.println("Invoking asyncComputation (thread id = " + Thread.currentThread().getId() + ")");
|
||||
// asyncComputation(new HelloWorld());
|
||||
|
||||
|
||||
HelloWorld hw = new HelloWorld();
|
||||
hw.setNameStr("fsdfs");
|
||||
System.out.println(HelloWorld.fetchNameStr(hw));
|
||||
HelloWorld hw = new HelloWorld();
|
||||
hw.setName("Jack");
|
||||
hw.no = 123434555L;
|
||||
hw.age = 30;
|
||||
System.out.println(HelloWorld.getFiled(hw));
|
||||
}
|
||||
|
||||
private String nameStr;
|
||||
|
||||
public void setNameStr(String nameStr){
|
||||
this.nameStr=nameStr;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getNameStr(){
|
||||
return nameStr;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void factCallback(int res) {
|
||||
System.out.println("factCallback: res = " + res);
|
||||
System.out.println("factCallback: res = " + res);
|
||||
}
|
||||
|
||||
public void counterCallback(int count) {
|
||||
System.out.println("counterCallback: count = " + count);
|
||||
System.out.println("counterCallback: count = " + count);
|
||||
}
|
||||
|
||||
public void asyncCallback(int progress) {
|
||||
|
Reference in New Issue
Block a user