Closed uvlad7 closed 7 months ago
@uvlad7 Hi, I didn't try to use non-static inner classes. I'll try it, but I know that non-static inner classes require outer (parent) class instance. Therefore you need to import the outer class separately. By the way, your java2jniname enhancement request is very reasonable. I'll change it. Thank you.
non-static inner classes require outer (parent) class instance
Yep, just implicit constructor param, that's it. Probably add this into docs
$ javac -d ./test Test.java && cd test && jar cvf ../test.jar ./* > /dev/null && cd .. && ruby test.rb
"TEST"
"NESTED_TEST"
"INNER_TEST"
"test"
"nested_test"
"inner_test"
Test.java
// javac -d ./test Test.java && cd test && jar cvf ../test.jar ./* && cd ..
public class Test {
public static String TEST = "TEST";
public String test;
public Test(String test) {
this.test = test;
}
public static String static_test() {
return TEST;
}
public String test() {
return this.test;
}
static class StaticNestedTest {
public static String NESTED_TEST = "NESTED_";
public String nested_test;
public StaticNestedTest(String nested_test) {
this.nested_test = nested_test;
}
public static String static_test() {
return NESTED_TEST + Test.TEST;
}
public String test() {
return this.nested_test /* + Test.this.test */ ;
}
}
class InnerTest {
public static String INNER_TEST = "INNER_";
public String inner_test;
public InnerTest(String inner_test) {
this.inner_test = inner_test;
}
public static String static_test() {
return INNER_TEST + Test.TEST;
}
public String test() {
return this.inner_test + Test.this.test;
}
}
}
test.rb
require 'rjb'
Rjb.load
Rjb.add_jar(File.expand_path('test.jar'))
Test = Rjb.import 'Test'
StaticNestedTest = Rjb.import 'Test$StaticNestedTest'
InnerTest = Rjb.import 'Test$InnerTest'
p Test.static_test
p Test.StaticNestedTest.static_test
p Test.InnerTest.static_test
p Test.new("test").test
p Test.StaticNestedTest.new("nested_test").test
p Test.InnerTest.new(Test.new("test"), "inner_").test
@uvlad7 I thought that RJB::import should take Java style parameter, not ruby style, nor JNI style. At this time, it requires '.' for the separator such as 'java.lang.String' not 'java::lang::String' or 'java/lang/String'(but it was accepted) as ruby and JNI do. For inner classes and nested classes (static inner classes), I like to apply the same convention. So I will implement your request with '.' as Java do.
StaticNestedTest = Rjb.import 'Test.StaticNestedTest'
InnerTest = Rjb.import 'Test.InnerTest'
Rjb may change '.' to '$' before the second capital letter token. Your opinion?
Yeah, it would be fine, just harder to implement, I suppose. I believe I've seen a function to convert these signatures somewhere, wasn't able to find it, though
Hi @uvlad7, I fixed this issue by rjb-1.7.0.gem. Now you can call with '.'. Thank you.
That's awesome, thank you for your efforts! It's really great to see such a long-lived project!
So, I tried to use
okhttp3.FormBody::Builder
, but it failsThe only way I found is to import it separately
after that
FormBody.Builder
works too. It's not an obvious way and I had to find howRjb.import
works internally (cls = (*jenv)->FindClass(jenv, name);
) to find a way to load it. Probablyjava2jniname
should replace"::"
with'$'
, but it still would require separateimport
. Is it possible to handle this inmethod_missing
? And will it work for non-static inner classes?