java/Ref: allow LocalRef to be nullable

Makes using the Java glue classes simpler to use, at the cost of very
little overhead.
This commit is contained in:
Max Kellermann 2019-04-11 11:32:07 +02:00
parent 791245dec2
commit 1d49f1108f

View File

@ -47,13 +47,13 @@ namespace Java {
public:
/**
* The local reference is obtained by the caller.
* The local reference is obtained by the caller. May
* be nullptr.
*/
LocalRef(JNIEnv *_env, T _value) noexcept
:env(_env), value(_value)
{
assert(env != nullptr);
assert(value != nullptr);
}
~LocalRef() noexcept {
@ -67,6 +67,10 @@ namespace Java {
return env;
}
operator bool() const noexcept {
return value != nullptr;
}
T Get() const noexcept {
return value;
}