java/Object: add Object.toString() wrapper

This commit is contained in:
Max Kellermann
2019-04-24 14:08:51 +02:00
parent 61b2ae0f7c
commit 72ebd5ebdd
4 changed files with 68 additions and 1 deletions

View File

@@ -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