I've struggled for a long time in #javagi with a good API for #GLib collection t...
Jan-Willem @jwh@social.tchncs.de
I've struggled for a long time in #javagi with a good API for #GLib collection types like GList, GSList, GHashTable. To properly marshal and dispose elements, requires a different approach for each type. For example, removing an owned GObject element needs a call to `g_object_unref()` but removing a string will need a simple `free()`. Boxed types have a predefined free function. The list goes on.
The solution I came up with is a "NativeOperations" interface with read(), alloc(), write(), copy() and free() methods. I implemented it for all common datatypes, and added a factory constructor for a given class name. Now I can create a list with strings using `new GList<String>(String.class)` and it will use the String operations.
Thanks @bugaevc for pointing me in this direction.