Skip to content

Commit 5381e61

Browse files
committed
Teach it how to deduce array signature
1 parent aef8766 commit 5381e61

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

jnipp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ namespace jni
7373

7474
// Foward Declarations
7575
class Object;
76+
template <class TElement> class Array;
7677

7778
/**
7879
This namespace is for messy implementation details only. It is not a part
@@ -103,6 +104,9 @@ namespace jni
103104
std::string valueSig(const Object* obj);
104105
inline std::string valueSig(const Object* const* obj) { return valueSig(obj ? *obj : nullptr); }
105106

107+
template <class TArg>
108+
inline std::string valueSig(const Array<TArg>*) { return "[" + valueSig((TArg*) nullptr); }
109+
106110
template <int n, class TArg>
107111
inline std::string valueSig(const TArg(*arg)[n]) { return valueSig((const TArg* const*)arg); }
108112

@@ -223,10 +227,6 @@ namespace jni
223227
*/
224228
JNIEnv* env();
225229

226-
// Forward declaration
227-
template <class TElement>
228-
class Array;
229-
230230
/**
231231
Object corresponds with a `java.lang.Object` instance. With an Object,
232232
you can then call Java methods, and access fields on the Object. To

tests/main.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,16 @@ TEST(Object_call_byNameWithArgs)
307307
TEST(Object_call_returningArray) {
308308
jni::Object str = jni::Class("java/lang/String").newInstance("Testing");
309309

310-
// TODO cannot deduce the right signature for an array
311-
auto getBytes =
312-
jni::Class("java/lang/String").getMethod("getBytes", "()[B");
313-
auto bytes = str.call<jni::Array<jni::byte_t>>(getBytes);
314-
ASSERT(bytes.getLength() == 7);
310+
{
311+
auto getBytes =
312+
jni::Class("java/lang/String").getMethod("getBytes", "()[B");
313+
auto bytes = str.call<jni::Array<jni::byte_t>>(getBytes);
314+
ASSERT(bytes.getLength() == 7);
315+
}
316+
{
317+
auto bytes = str.call<jni::Array<jni::byte_t>>("getBytes");
318+
ASSERT(bytes.getLength() == 7);
319+
}
315320
}
316321

317322
TEST(Object_makeLocalReference)

0 commit comments

Comments
 (0)