Java APIs: Add a Builder interface implemented by all Builders #1652
Labels
effort/small
Small work item – less than a day of effort
feature-request
A feature should be added or improved.
language/java
Related to Java bindings
module/pacmak
Issues affecting the `jsii-pacmak` module
p2
In Java, each Builder class should implement a generic Builder interface.
Use Case
We can use extension methods in Kotlin to make it less verbose to build props, like this:
which works by using this extension method:
Unfortunately, the extension method has to use unsafe reflection and casting due to there being no relationship in the type system between Builders and the types they build.
A simple Builder interface would help make helper methods like these simpler and type-safe, like this:
Proposed Solution
The Java API should include this interface:
and each Builder class should implement it:
Other
This should be backwards-compatible for almost all cases. In theory, it simply adds an interface for functions that are already present. In the wild, if some code relies on the fact that Builder classes don't implement an interface, that code may break.
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: