diff options
Diffstat (limited to 'platform/android/src/java')
-rw-r--r-- | platform/android/src/java/util.hpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/platform/android/src/java/util.hpp b/platform/android/src/java/util.hpp index 808f14be15..9b0c01459e 100644 --- a/platform/android/src/java/util.hpp +++ b/platform/android/src/java/util.hpp @@ -14,10 +14,11 @@ public: static constexpr auto Name() { return "java/util/List"; }; template<class T> - static jni::Array<jni::Object<T>> toArray(jni::JNIEnv& env, jni::Object<List> list) { - static auto javaClass = jni::Class<List>::Singleton(env); + static jni::Local<jni::Array<jni::Object<T>>> toArray(jni::JNIEnv& env, const jni::Object<List>& list) { + static auto& javaClass = jni::Class<List>::Singleton(env); static auto toArray = javaClass.GetMethod<jni::Array<jni::Object<>> ()>(env, "toArray"); - return (jni::Array<jni::Object<T>>) list.Call(env, toArray); + + return jni::Local<jni::Array<jni::Object<T>>>(env, list.Call(env, toArray).release()); }; }; @@ -26,10 +27,12 @@ public: static constexpr auto Name() { return "java/util/Arrays"; }; template <class T> - static jni::Object<List> asList(jni::JNIEnv& env, jni::Array<jni::Object<T>> array) { - static auto javaClass = jni::Class<Arrays>::Singleton(env); + static jni::Local<jni::Object<List>> asList(jni::JNIEnv& env, const jni::Array<jni::Object<T>>& array) { + static auto& javaClass = jni::Class<Arrays>::Singleton(env); static auto asList = javaClass.GetStaticMethod<jni::Object<List>(jni::Array<jni::Object<>>)>(env, "asList"); - return javaClass.Call(env, asList, (jni::Array<jni::Object<>>) array); + + auto typeErasedArray = jni::Local<jni::Array<jni::Object<>>>(env, jni::NewLocal(env, array).release()); + return javaClass.Call(env, asList, typeErasedArray); } }; @@ -38,10 +41,11 @@ public: static constexpr auto Name() { return "java/util/Set"; }; template<class T> - static jni::Array<jni::Object<T>> toArray(jni::JNIEnv& env, jni::Object<Set> list) { - static auto javaClass = jni::Class<Set>::Singleton(env); + static jni::Local<jni::Array<jni::Object<T>>> toArray(jni::JNIEnv& env, const jni::Object<Set>& list) { + static auto& javaClass = jni::Class<Set>::Singleton(env); static auto toArray = javaClass.GetMethod<jni::Array<jni::Object<>> ()>(env, "toArray"); - return (jni::Array<jni::Object<T>>) list.Call(env, toArray); + + return jni::Local<jni::Array<jni::Object<T>>>(env, list.Call(env, toArray).release()); }; }; @@ -54,15 +58,15 @@ public: static constexpr auto Name() { return "java/util/Map$Entry"; }; template <class T> - static jni::Object<T> getKey(jni::JNIEnv& env, jni::Object<Entry> entry) { - static auto javaClass = jni::Class<Map::Entry>::Singleton(env); + static jni::Local<jni::Object<T>> getKey(jni::JNIEnv& env, const jni::Object<Entry>& entry) { + static auto& javaClass = jni::Class<Map::Entry>::Singleton(env); static auto method = javaClass.GetMethod<jni::Object<> ()>(env, "getKey"); return jni::Cast(env, jni::Class<T>::Singleton(env), entry.Call(env, method)); } template <class T> - static jni::Object<T> getValue(jni::JNIEnv& env, jni::Object<Entry> entry) { - static auto javaClass = jni::Class<Map::Entry>::Singleton(env); + static jni::Local<jni::Object<T>> getValue(jni::JNIEnv& env, const jni::Object<Entry>& entry) { + static auto& javaClass = jni::Class<Map::Entry>::Singleton(env); static auto method = javaClass.GetMethod<jni::Object<> ()>(env, "getValue"); return jni::Cast(env, jni::Class<T>::Singleton(env), entry.Call(env, method)); } |