-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRustJavaRust.java
76 lines (63 loc) · 2 KB
/
RustJavaRust.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Compile this file with:
*
* javac Test.java
*
* The Java method signatures can be seen using the Java command-line tool `javap`:
*
* javap -s Test.class
*/
class RustJavaRust {
private int uid = 10;
public native void call_from_java();
public native void call_from_java_with_int(int a);
public native byte[] call_from_java_with_byte_array(byte[] input);
public native void call_from_java_with_byte_array_arg(byte[] input);
public RustJavaRust() {
System.out.println("Java: Constructor called");
call_rust();
}
public void call_rust() {
System.out.println("Java: Calling rust methods");
call_from_java();
call_from_java_with_int(uid);
call_from_java_with_byte_array_arg("test".getBytes());
byte[] outputByte = call_from_java_with_byte_array("byte".getBytes());
System.out.println("Java: Returned array length from rust is "+outputByte.length);
}
public static void main(String [] args) {
}
public static void println(Object object) {
System.out.println(object);
}
public static boolean static_method_that_returns_a_boolean(boolean arg) {
return !arg;
}
public static byte static_method_that_returns_a_byte() {
return 42;
}
public static char static_method_that_returns_a_char() {
return 'a';
}
public static double static_method_that_returns_a_double() {
return 42.0f;
}
public static float static_method_that_returns_a_float() {
return 42.0f;
}
public static int static_method_that_returns_a_int() {
return 42;
}
public static long static_method_that_returns_a_long() {
return 42L;
}
public static String static_method_that_returns_a_string() {
return new String("Foo");
}
public static String static_method_that_returns_an_interned_string() {
return "Foo";
}
public static void static_void_method() {
System.out.println(":)");
}
}