jwharm / java-gi

GObject-Introspection bindings generator for Java
GNU Lesser General Public License v2.1
93 stars 9 forks source link

Add no-argument constructor in case of ambiguous overload #123

Closed jwharm closed 2 months ago

jwharm commented 2 months ago

For example: a new Gtk Frame can be constructed with:

public Frame(@Nullable String label)

The label argument is optional, and will often be null. However, because all Java-GI classes contain a constructor with a single MemorySegment argument, the null argument must be explicitly cast to String like this:

var frame = new Frame((String) null);

or for example in Scala:

val frame = Frame(null.asInstanceOf[String])

This can be resolved by generating an extra constructor in this case, that simply calls this((String) null);