0.8.0
This release upgrades the Java bindings to OpenJDK 21! This is an incompatible change from Java-GI 0.7.x, because the Panama FFI API changed significantly since JDK 20. The JDK 21 version (JEP 442) is the last preview version though; in JDK 22 the API will be final!
Kotlin users must upgrade to Kotlin 1.9.20 or newer if they want to use Java-GI 0.8.0, because older Kotlin releases are incompatible with JDK 21.
Notable changes:
GNOME 45
All libraries have been upgraded to the versions of the GNOME 45 SDK and Freedesktop SDK 23.08. See the README.md for the exact version numbers.
Allocate structs with an Arena
The Panama FFI in its current form heavily uses memory arenas to manage allocation lifetimes. Users can choose between different arenas, depending on your use case. Therefore, the allocate()
methods generated by Java-GI for record (struct) and union types now expect an Arena as the first parameter.
Example:
try (var arena = Arena.ofConfined()) {
var red = RGBA.allocate(arena, 1.0, 0.0, 0.0, 0.0);
// memory is now allocated
}
// memory is now deallocated
var blue = RGBA.allocate(Arena.ofAuto(), 0.0, 0.0, 1.0, 0.0);
// memory will be deallocated when the variable is garbage collected
var green = RGBA.allocate(Arena.global(), 0.0, 1.0, 0.0, 0.0);
// memory will be allocated during the entire application runtime
Read the Arena documentation for more information.
To ease the transition, the old allocate()
methods without an Arena parameter are still available. These methods use an Arena.ofAuto()
behind the scenes. Dealing with native memory deallocations during GC is rather ugly, so I don't want users to think this is the default option. Therefore, these methods have been marked as deprecated
, and will be removed in the next Java-GI release.
Property names will be inferred by default
In a GObject-derived class, you can define custom properties with a @Property
annotation on the getter and setter methods. With Java-GI 0.8.0, the name
parameter of the annotation has become optional. If you don't specify a name, it will be inferred from the getter and setter method name (converting setMyProperty
to my-property
).
Builder syntax has changed
The setter methods in the Builder classes now start with a set...
prefix. This allows the builders to be used as Java Beans, allowing a much nicer property assignment syntax in Kotlin. The old setters are still available, but deprecated, and will be removed in the next Java-GI release.
Shorter constructor names
The new
prefix in named constructors doesn't really serve a purpose in Java, and has been removed. As an example, gtk_button_new_with_label()
will no longer be available as Button.newWithLabel()
, but Button.withLabel()
. As with the other API changes, the old syntax (Button.newWithLabel()
) is still available, but deprecated, and will be removed in the next Java-GI release.
Improved HarfBuzz type names
HarfBuzz types have a "_t" postfix in C, which was previously mapped to Java classes like FontT
. The trailing "T" is now gone.
Improved handling of callback memory allocations
The Panama FFI needs an explicit memory allocation to a expose Java callback method to native code. These are now deallocated automatically, as specified in scope
attribute in GObject-Introspection.
Improved binding of virtual methods
In previous versions, Java-GI mapped virtual methods to regular public Java methods. This is incorrect; virtual methods are not designed as an API, but can be used to "chain up" when implementing a derived class. This is why in PyGObject for example, virtual methods have a do_
prefix to prevent confusion with regular methods. In Java-GI 0.8.0, virtual methods are now exposed with protected
visibility. You can "chain up" using the asParent()
API that was implemented in Java-GI 0.7.0.
Upgraded and improved Cairo bindings
Not part of Java-GI, but related: The manually developed cairo bindings have also been upgraded to JDK 21, and now also support user-defined fonts.
More details in the PRs:
- Inferred property names by @jwharm in #73
- Upgrade cairo to 1.18.0 by @jwharm in #74
- Port to JDK 21 by @jwharm in #75
- Callback lifetimes by @jwharm in #76
- Use setter syntax in builder classes by @jwharm in #77
- Generate better Harfbuzz type names by @jwharm in #78
- Improve virtual methods by @jwharm in #79
- Shorter constructor names by @jwharm in #80
Full Changelog: 0.7.2...0.8.0