java/Object: add Object.toString() wrapper
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2010-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace Java {
|
||||
/**
|
||||
* Wrapper for a local "jobject" reference.
|
||||
@@ -51,6 +53,24 @@ namespace Java {
|
||||
GlobalObject(JNIEnv *env, jobject obj) noexcept
|
||||
:GlobalRef<jobject>(env, obj) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Utilities for java.net.Object.
|
||||
*/
|
||||
class Object {
|
||||
static jmethodID toString_method;
|
||||
|
||||
public:
|
||||
static void Initialise(JNIEnv *env);
|
||||
|
||||
static jstring toString(JNIEnv *env, jobject o) {
|
||||
assert(env != nullptr);
|
||||
assert(o != nullptr);
|
||||
assert(toString_method != nullptr);
|
||||
|
||||
return (jstring)env->CallObjectMethod(o, toString_method);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user