The most common answer is to show the result as an unbouned C array in Java:
%module test %include "carrays.i" %array_class(unsigned char, ucArray); unsigned char *getFoo();
This generates a class called ucArray , which gets and sets for a specific index. It is unlimited, with the same semantics as C-arrays, but easy and convenient. Since it is not limited, you can call Undefined Behavior from Java, and it has no boundaries, which makes it impossible to use as an Iterator or Collection .
If your array is NULL / 0 complete, it would be wise to just use %extend to implement the Java Iterable interface, a crude, unchecked example:
%typemap(javainterfaces) ucArray "java.lang.Iterable<Short>" %typemap(javacode) ucArray %{ public java.util.Iterator<Short> iterator() { return new java.util.Iterator<Short>() { private int pos = 0; public Short next() {
This needs to be moved somewhere before the %array_class macro is called. It says that our ucArray class implements Iterable , and then implements this interface using the anonymous inner class in iterator() (the only Iterable interface method) to implement the Iterator interface.
source share