A modern, type-safe, header-only, C++14 wrapper for JNI
OTHER License
Bot releases are hidden (Show)
This release contains many breaking changes in the high-level API, especially around ownership semantics.
UniqueObject
and UniqueWeakObject
with Global
and Weak
, and introduced Local
. All high-level values must be one of these three types; high-level references (e.g. const jni::Object<>&
) must now be used whenever borrowing, rather than ownership, is desired. In particular, native method implementations should accept non-primitive inputs via reference, rather than by value.Local
ownership type, which calls DeleteLocalRef
when destroyed. You'll never need to worry about overflowing the local ref table.Object
, Class
, and Array
are no longer publicly constructible, destructible, movable, copyable, assignable, or implicitly convertible to raw pointers. Use Global
, Weak
, and Local
for ownership. Use MakeGlobal
, MakeWeak
, and MakeLocal
for explicit ref duplication. Use C++ references when borrowing, rather than ownership, is desired. Avoid using raw pointers when possible; use get()
if you really need one.Object
, enabling convenient automatic conversions. To inform jni.hpp of Java inheritance, add a SuperTag
typedef to a tag type naming the tag type for the Java superclass, e.g.:
struct StringTag { using SuperTag = ObjectTag; ... };
String
, Class
, and Array
now inherit from Object<>
.ArrayTag<T>
, where T
is a primitive or high-level type. This allows you to obtain array classes, e.g. Class<ArrayTag<jni::jlong>>::Singleton(env)
.Cast
.Other new features:
Class<Tag>::Singleton()
, providing a convenient way to obtain a reference to a Class
instance.Array<jbyte>
<-> std::string
conversions.TypeSignature
implementation.Global
and Weak
that attach or get the JNIEnv
. These are useful when the deletion will happen on an auxiliary thread, such as the finalizer thread.java.lang.ref.WeakReference
. This should almost always be used instead of JNI weak global refs, which have unsafe promotion semantics.Bugfixes:
AttachCurrentThread
Published by jfirebaugh over 8 years ago
jni::PushLocalFrame
is now an ownership type. Accordingly, jni::PopLocalFrame
now accepts ownership.Published by jfirebaugh over 8 years ago
Initial release.