You need to use jni api to find HashMap
java class, then its methods for construction and insertion of elements. Then Add all the elements and finally return this map. It should look as follows (warning - pseudocode !!!)
env->PushLocalFrame(256); // fix for local references
jclass hashMapClass= env->FindClass(env, "java/util/HashMap");
jmethodID hashMapInit = env->GetMethodID(env, hashMapClass, "<init>", "(I)V");
jobject hashMapObj = env->NewObject(env, hashMapClass, hashMapInit, mMap.size());
jmethodID hashMapOut = env->GetMethodID(env, hashMapClass, "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
for (auto it : mMap)
{
env->CallObjectMethod(env, hashMap, put,
env->NewStringUTF(it->first.c_str()),
env->NewStringUTF(it->second.c_str()));
}
env->PopLocalFrame(hashMap);
return hashMap;
ps. I usually code jni under android, but above code should work the same under other platforms.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…