You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [java-gi-app-template](https://github.com/jwharm/java-gi-app-template) repository offers a ready-to-run GNOME application template with translations, resources, settings, icons and much more. The template is setup to be built and installed as a Flatpak application.
87
+
87
88
## Generate bindings for other libraries
88
89
89
90
Java-GI offers a command-line utility to generate bindings for any library that supports GObject-Introspection. It is documented [here](https://jwharm.github.io/java-gi/generate/).
@@ -116,7 +117,7 @@ Interfaces are mapped to Java interfaces, using `default` interface methods to c
116
117
117
118
Type aliases (`typedef`s in C) for classes, records and interfaces are represented in Java with a subclass of the original type. Aliases for primitive types such as `int` or `float` are represented by simple wrapper classes.
118
119
119
-
Enumerations are represented as Java `enum` types, and flag parameters are mapped to `EnumSet`.
120
+
Enumerations are represented as Java `enum` types, and flag (bitfield) parameters are mapped to `EnumSet`.
120
121
121
122
Most classes have one or more constructors. However, constructors in GTK are often overloaded, and the name contains valuable information for the user. Java-GI therefore maps constructors named "new" to regular Java constructors, and generates static factory methods for all other constructors:
122
123
@@ -131,7 +132,7 @@ var button2 = Button.withLabel("Open...");
131
132
var button3 =Button.fromIconName("document-open");
132
133
```
133
134
134
-
Some struct types (called "records" in GObject-Introspection) don't have constructors, because in C these are meant to be stack-allocated. An example is `Gdk.RGBA`. Java-GI adds constructors that will allocate a new struct in an [Arena](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/foreign/Arena.html) of your choice. You can either allocate an empty struct (`var color = new RGBA();`) and fill in the values later, or pass the values immediately: `var purple = new RGBA(0.9f, 0.1f, 0.9f, 1.0f);`
135
+
Many struct types don't have constructors, because in C they are meant to be stack-allocated. Java-GI adds constructors that will allocate a new struct in an [Arena](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/foreign/Arena.html) of your choice. You can either allocate an empty struct (`var color = new RGBA();`) and fill in the values later, or pass the values immediately: `var purple = new RGBA(0.9f, 0.1f, 0.9f, 1.0f);`
For every signal, a method to connect (e.g. `onClicked`) and emit the signal (`emitClicked`) is included in the API. New signal connections return a `SignalConnection` object, that allows you to disconnect, block and unblock a signal, or check whether the signal is still connected.
146
147
147
-
Functions with callback parameters are supported too. The generated Java bindings contain `@FunctionalInterface` definitions for all callback functions to ensure type safety.
148
+
Functions with callback parameters are supported too. The generated Java bindings contain `@FunctionalInterface` definitions for all callbacks to ensure type safety.
148
149
149
-
[Closures](https://docs.gtk.org/gobject/struct.Closure.html)are marshaled to Java methods using reflection.
150
+
Java-GI can create [GClosures](https://docs.gtk.org/gobject/struct.Closure.html)(dynamically-typed callbacks) using the [JavaClosure](https://java-gi.org/javadoc/org/javagi/gobject/JavaClosure.html) class, which uses reflection to marshal and unmarshal method- or lambda parameters to and from `GValues ` as required for a GClosure.
150
151
151
152
### Registering new types
152
153
@@ -155,6 +156,7 @@ Java-GI registers GObject-derived Java classes as a GType. When overriding virtu
155
156
```java
156
157
publicclassPlayerextendsGObject {
157
158
privateString name;
159
+
privateint lives;
158
160
159
161
publicintgetLives() {
160
162
return lives;
@@ -204,7 +206,7 @@ You can read more about template classes in [the documentation](https://jwharm.g
204
206
205
207
Java-GI takes care of marshaling Java values from and to native values. When working with arrays, Java-GI will automatically copy native array contents from and to a Java array, marshaling the contents to the correct types along the way. A `null` terminator is added where applicable. You also don't need to specify the array length as a separate parameter.
206
208
207
-
Nullability of parameters (as defined in the GObject-introspection attributes) is indicated with `@Nullable` and `@NotNull` attributes, and checked at runtime. The nullability attributes are imported from Jetbrains Annotations (as a compile-time-only dependency).
209
+
Nullability of parameters (as defined in the GObject-introspection attributes) is indicated with JSpecify `@NullMarked` and `@Nullable` attributes, and checked at runtime.
208
210
209
211
Variadic functions (varargs) are supported too:
210
212
@@ -227,8 +229,9 @@ Out-parameters are mapped to a simple `Out<T>` container-type in Java, that offe
0 commit comments