[Foreign(Language.Java)]
public static extern(Android) void Init()
{
// ...
byte[] data = getData();
@{Process(sbyte[]):Call(data)};
}
[Foreign(Language.Java)]
public static extern(Android) void Process(sbyte[] data)
{
// work with data
}
And then it notified this error: byte[] cannot be converted to ByteArray
I have raised a ticket to fix this and will get on it as soon as I can.
The reason we box uno arrays when passing to java is for performance. We want to avoid unnecessary data copying by default and so we box into a com.uno._Type_Array that boxed array has accessors and a copyArray() method which will actually duplicate the data.
Like you worked out, currently foreign code is expecting a com.uno.ByteArray to be passed to uno. I’m now wondering if maybe we allow both this and java arrays, and just take the performance hit when we pass down the java array.
Thanks again, I’ll be in contact when there is a fix.
Ah I think I have confused things copyArray is a method on the ByteArray java object.
[Foreign(Language.Java)]
public void TestByteArray(byte[] foo)
@{
// here foo is a com.uno.ByteArray. This is a java box
// around the Uno byte[]
byte x = foo.get(0);
// here we get the first byte from the array. This calls
// down to uno to read the uno array so far we have not
// copied any data
foo.set(0, 3);
// now we set the first byte in the uno array. This
// modified the uno array
byte[] bar = foo.copyArray();
// At this point we copy the entire array into Java memory.
// making changes to bar will not modify the uno array
@}