A while ago I solved a similar task by creation of a custom read-only "vector-like" class with at()
method exposed as get(int i)
on java level. The main idea is that you don't have to have the same class on native and swig level. Actually you construct SWIG-level almost independently from C/C++ level. The key method of the construction is %extend
SWIG-directive, something like this:
%{
#include "session.h"
%}
%extend session {
const media& getMedia(int i) {
return media[i];
}
}
But be aware, that while performing tricks like that I literally felt that I was doing something really evil. Like studying The Dark Forces from "Harry Potter" ;-) And afterall, I discovered that doing a lot of Java<->native code switches performs not that good as expected.
Also I doubt you could return an "array object" from native code and use it safely from Java, because such an access heavily depends on low-level data alignment, and you don't have methods to directly translate C-level data to Java-level data without extra copyings