Change request: do not geenrate constructors with object varargs #213
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
java
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
java-gi/java-gi#213
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello, fir of all, thanks for the amazing library!
I'm the author of compose-4-gtk, a library to instantiate the GTK/ADW widgets in the style of Kotlin Compose, for example:
While upgrading from JavaGI
v0.11to0.12, I noticed that the new constructors on GObjects that takeObject... propertyNamesAndValuescause a lot of confusion for users of my library.For example, in the example above, importing by mistake
org.gnome.gtk.Labelwon't raise any compilation error, but will crash at runtime, sinceModifieris not a supported property.In general, the new signatures are very broad, and not type safe.
I have some suggestions:
Label.fromProperties(Object... propertyNamesAndValues)propertyNamesAndValueshas to be a string, why not changing the signature toString propertyName, Object... propertyValues? This, plus an empty constructor, should offer the same feature, with a bit more safety.I think the first suggestion would be the best one. What do you think?
Thanks!
Thanks for the feedback!
I didn't realize that the varargs constructor would have such negative consequences, but I agree that this is confusing.
The most important consideration for me, is that I want to have a no-argument constructor to make subclassing as easy as possible. If we change the varargs constructor into a static function, the only constructor that will always be left, is the one that takes a MemorySegment.
So I'd prefer to change the
String propertyName, Object... propertyValuesversion into a factory method, and keep the no-args constructor. OK?Thanks, that works!
I think we even work without the factory method. There's already
GObject.newInstance(Class<T>, Object... properties)that can be used for exactly this purpose, so I don't see the need for an extra constructor in every class.PR #215 changes the varargs constructor into a no-args constructor.
Thanks for making the change :)
The fix is in release 0.12.1-RC1. Can you please let me know if it works for you? Thanks in advance.
Can I download
0.12.1-RC1from Maven?Alternatively, are the generated sources published somewhere?
I tried to generate the sources myself, but I get errors like
No GIR files found for Gdk. Do you have a guide on how to set up the project?Yes, the RC version is on Maven Central so you can just change the version of the dependency.
The generated sources aren’t checked into git, but there are sources.jar on Maven Central. To generate them yourself, clone the java-gi repo with the
--recurse-submodulesoption. See the bottom of this page for complete instructions: https://jwharm.github.io/java-gi/generate/Okay, I tried the new version. It works perfectly. Now it's impossible to create a GTK widget by mistake.
Thanks!