This release contains many breaking changes in the high-level API, especially around ownership semantics.
- Replaced
UniqueObjectandUniqueWeakObjectwithGlobalandWeak, and introducedLocal. 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. - High-level JNI local refs are now always wrapped with the
Localownership type, which callsDeleteLocalRefwhen destroyed. You'll never need to worry about overflowing the local ref table. Object,Class, andArrayare no longer publicly constructible, destructible, movable, copyable, assignable, or implicitly convertible to raw pointers. UseGlobal,Weak, andLocalfor ownership. UseMakeGlobal,MakeWeak, andMakeLocalfor explicit ref duplication. Use C++ references when borrowing, rather than ownership, is desired. Avoid using raw pointers when possible; useget()if you really need one.- If you tell jni.hpp about the Java inheritance tree, it'll build a parallel tree for
Object, enabling convenient automatic conversions. To inform jni.hpp of Java inheritance, add aSuperTagtypedef to a tag type naming the tag type for the Java superclass, e.g.:struct StringTag { using SuperTag = ObjectTag; ... };
- As special cases of the above,
String,Class, andArraynow inherit fromObject<>. - Introduced
ArrayTag<T>, whereTis a primitive or high-level type. This allows you to obtain array classes, e.g.Class<ArrayTag<jni::jlong>>::Singleton(env). - Swapped the argument order for
Cast. - Removed an annoying parameter to Array::New.
Other new features:
- Introduced
Class<Tag>::Singleton(), providing a convenient way to obtain a reference to aClassinstance. - Added wrappers for boxing and unboxing primitive types.
- Support for
Array<jbyte><->std::stringconversions. - More efficient
TypeSignatureimplementation. - Added deleters for
GlobalandWeakthat attach or get theJNIEnv. These are useful when the deletion will happen on an auxiliary thread, such as the finalizer thread. - Added a wrapper for
java.lang.ref.WeakReference. This should almost always be used instead of JNI weak global refs, which have unsafe promotion semantics.
Bugfixes:
- Cope with implementation inconsistencies in
AttachCurrentThread - Improved compatibility with OpenJDK
- Improved compatibility with GCC