I tried to implement the same function in Java:
I don't understand what you mean. Are you trying to provide a Java implementation of the C++ code or are you trying to call the C++ code from your Java code.

Unfortunately the Java code you have shown makes little sense unless you show/explain what a JIString is and what object type 'dispatch' is and what it's callMethod() method does.