You have made me recall nightmares from my previous job while researching the answer to your question :).
I chose to avoid this problem instead of solving it. I'd create a dead simple C++ class like
class ArrayAdapter
{
public:
int size();
MyClass *getItem(int index);
};
and then
ArrayAdapter myFunction();
If you need to pass it into a Java function that expects an array or Collection
, write the wrapper code in Java.
I don't claim this is the best solution, but sometimes it's nicer to write something simple and debuggable rather than relying on SWIG typemap magic.