Listing 3

--------- jni_entry.h ---------
 ...
typedef pair< string, func_variant > functionName2Functor;
static unsigned _i1_i = 0; // counter
#define REGISTER_FUNCTOR_TO_MAP( x ) \
(++_i1_i,functionName2Functor( #x, func_variant( &x ) ))

--------- test_jni.cpp ---------
static functionName2Functor arrNamedFunctors[] = {
REGISTER_FUNCTOR_TO_MAP( CMyClass::getString ),
REGISTER_FUNCTOR_TO_MAP( testPtr ),
REGISTER_FUNCTOR_TO_MAP( testVector ) 
};
static map<string,func_variant> map_name2functor( &arrNamedFunctors[0],
   &arrNamedFunctors[_i1_i] );
func_variant& get_functor(const char* name ){
    map<string,func_variant>::iterator it = map_name2functor.find( name );
    if( it != map_name2functor.end() ){
        return (*it).second;
    }
    dout << "\nfunction " << name << " was not found";
    throw (string( "this function was not found:\n") + name );
}
-------- GenericCall2CLib.java ---------
public static void main (String[] args)
{
      try {
            System.out.println( invoke1( "test", new Integer(121) ) );
            GenericCall2CLib func1 = new GenericCall2CLib( "test" );
            func1.addArg(122);
            System.out.println( func1.invoke() );
    ...
    }
 ...
}