From b7e0f45a857117ede71cb91ac66e5650ee346952 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 20 Oct 2023 22:07:19 +0200 Subject: [PATCH] JNI: simplify code for declared types a bit Template type is implied, and forwarding to QJniObject implementations avoids code duplication. Change-Id: I7c25c93a7fdf20de7a4c61129d9383f0f6f508c7 Reviewed-by: Assam Boudjelthia --- src/corelib/kernel/qjnitypes.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/corelib/kernel/qjnitypes.h b/src/corelib/kernel/qjnitypes.h index bedf368e30..dfde8c7244 100644 --- a/src/corelib/kernel/qjnitypes.h +++ b/src/corelib/kernel/qjnitypes.h @@ -28,10 +28,10 @@ struct Object : QJniObject Q_IMPLICIT Object(QJniObject &&object) : QJniObject(std::move(object)) {} // Compiler-generated copy/move semantics based on QJniObject's shared d-pointer are fine! - Object(const Object &other) = default; - Object(Object &&other) = default; - Object &operator=(const Object &other) = default; - Object &operator=(Object &&other) = default; + Object(const Object &other) = default; + Object(Object &&other) = default; + Object &operator=(const Object &other) = default; + Object &operator=(Object &&other) = default; // avoid ambiguities with deleted const char * constructor Q_IMPLICIT Object(std::nullptr_t) : QJniObject() {} @@ -41,18 +41,13 @@ struct Object : QJniObject , ValidSignatureTypes = true > explicit Object(Args &&...args) - : QJniObject(Qt::Initialization::Uninitialized) - { - *this = Object{QJniObject::construct(std::forward(args)...)}; - } + : QJniObject(QtJniTypes::Traits::className(), std::forward(args)...) + {} // named constructors avoid ambiguities - static Object fromJObject(jobject object) { return Object(object); } + static Object fromJObject(jobject object) { return Object(object); } template - static Object construct(Args &&...args) - { - return Object{QJniObject::construct(std::forward(args)...)}; - } + static Object construct(Args &&...args) { return Object{std::forward(args)...}; } // public API forwarding to QJniObject, with the implicit Class template parameter template