From a2fed9771a9eaae65b2ab2066af9774d9bebf1c7 Mon Sep 17 00:00:00 2001 From: wang-bin Date: Sat, 4 May 2024 17:21:40 +0800 Subject: [PATCH] error ref --- jmi.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jmi.h b/jmi.h index 543295a..bce3088 100644 --- a/jmi.h +++ b/jmi.h @@ -1,6 +1,6 @@ /* * JMI: JNI Modern Interface - * Copyright (C) 2016-2023 Wang Bin - wbsecg1@gmail.com + * Copyright (C) 2016-2024 Wang Bin - wbsecg1@gmail.com * https://github.com/wang-bin/JMI * MIT License */ @@ -167,7 +167,7 @@ class JObject : public ClassTag operator jclass() const { return classId();} jobject id() const { return oid_; } explicit operator bool() const { return !!oid_;} - string error() const {return error_;} + const string& error() const {return error_;} JObject& reset(jobject obj = nullptr, JNIEnv *env = nullptr); template @@ -275,7 +275,7 @@ class JObject : public ClassTag } private: static jclass classId(JNIEnv* env = nullptr); - JObject& setError(string&& s) const { + JObject& setError(const string& s) const { error_ = std::move(s); return *const_cast(this); } @@ -980,8 +980,7 @@ JObject& JObject::reset(jobject obj, JNIEnv *env) { if (!env) return setError("Invalid JNIEnv"); } - if (oid_) - env->DeleteGlobalRef(oid_); + env->DeleteGlobalRef(oid_); // can be null oid_ = nullptr; if (obj) { oid_ = env->NewGlobalRef(obj);