Closed bertung closed 2 years ago
This question is related to #433.
The JVM does not allow creating arrays with mixted types. So it is not possible to create an array containing booleans and ints. However, it is possible to create an array of type Object[] and store an integer primitive in it. The compiler will apply autoboxing, and convert the int primitive to a java.lang.Integer instance, which can be safely stored in an Object[] arrays.
The OpaqueReferenceType and the OpaqueReferenceArray support a different use case. OpaqueReferenceType is the base type for everything not implemented but used by JVM classes. This might be something like the browser console, a promise or even a HTML DOM element. So all if this is some kind of reference used by JVM code.
The OpaqueReferenceArray is not designed to store primitive datatypes. Can you please elaborate your usecase?
Please see org.teavm.jso.core.JSArray.java for a possible use case to convert and pass a Java object array to Javascript.
You can always pass a Object[] array to an impored JavaScript function, but you will get no auto-unboxing etc. All type conversions have to be done on JS side.
So can you please elaborate your usecase why to want to use an OpaqueReferenceType? Please help me so I can help you!
I need to pass a large raw mixed Javascript array from Bytecoder instead of passing a large JSON string for performance. Mixed array would only include primitive types, strings or other mixed arrays (they may include nested arrays as well) in its structure. Although I mentioned it in this question, I am not particularly after OpaqueReferenceType to use. Any other feature in the API that may help me accomplish this will do.
Closed due to no further interaction.
How to convert int,double,String and boolean to OpaqueReferenceType?
OpaqueReferenceArray array=OpaqueArrays.createObjectArray(); //how to use array.push(5); array.push("hey"); array.push(true); array.push(5.6);