I haven’t seen this anywhere (or maybe I’m jsut simple not seeing it) but is there a way to use JNI to return the c/c++ object and use that object in java?
For example (very simple):
class simpleClass{
...
private:
int intVar;
public:
int getIntVar();
void setIntVar(int someNum);
...
}
In my java code, how would I go about doing something like:
...
simpleClass sc = new simpleClass();
sc.setIntVar(9);
System.out.println(sc.getIntVar());
...
I realize this is a VERY simplistic example but I’m just looking for concept – the class I have in mind that is in c++ is very large and am looking to avoid creating a TON of wrapper methods…
If it’s not possible that’s fine, just hoping to save a few days coding lol
No you can’t. The C++ and Java ABIs are completely different – for one, c++ doesn’t define one. And really c++ has so many features that can’t be mapped to Java at all this just can’t work. How do you expect Java would handle c++ templates? Pointers to primitives? Objects that aren’t pointers?
Now what you can do, is use SWIG to generate the right wrapper methods for you – that will actually work and is not much more work than what you planned 🙂