Rework constructor generation #339
No reviewers
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!339
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "rework-constructors"
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?
Most classes generated by Java-GI extend the
ProxyInstancebase class which has apublic ProxyInstance(MemorySegment address)constructor for the native memory address. This means all classes generated by Java-GI, in their constructor, must call the base constructor with the native address.In older Java releases (before JDK 25), the
super()keyword was required to be the first statement in a constructor. So we couldn't do this:Because the
super()keyword must be the first statement.So Java-GI generated a static helper method:
With JEP 513 "Flexible Constructor Bodies", we can construct the native instance before calling
super(), and the private staticconstructNew()helper methods will not be generated anymore.For consistency and code reuse, the constructors are now generated in the MethodGenerator class. The ConstructorGenerator class has been removed.