eclipsesource / J2V8

Java Bindings for V8
2.54k stars 355 forks source link

how can i pass java object in javascript and create new object in javascript? #585

Open xjl2020 opened 1 year ago

xjl2020 commented 1 year ago

use j2v8 in android: class A{ public C methodA1(B b) { return b.methodB1(); }

public B methodA2() {
    return new B();
}

}

class B{

public C methodB1(){
    return new C();
}

}

class C{ public void methodC1(){

}

}

then,what should i do to resolve this, i use registerJavaMethod but it report error like this:

Unknown return type: class

if use V8JavaAdapter.injectclass then can create new object like: let b1 = new B();

and in java:

v8 = V8.createV8Runtime(); V8Object v8Console = new V8Object(v8); v8.add('A',v8Console); v8Console.registerJavaMethod(value, method.getName(), method.getName(), parameterTypes); -- register A methodA1 then i use A.methodA1(b1) it report error: has argument 1 has type B, got com.eclipsesource.v8.V8Object, how to resolve it , Thank you!!