You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a JavaTemplate it should be possible to optionally specify a target type (as defined in the JLS). This is for example necessary when the template expression is only a method reference or a lambda and would unlock further Refaster use cases as well as declaring some more templates as context-free (like this example).
This idea would be for the JavaTemplate.Builder to declare a new targetType() method. Whether the parameter's type should be a plain String, JavaType, or even have both overloads would have to be explored.
An example would be a template like () -> 3 which would not be usable as a context-free template unless a matching target type like Supplier<Integer> is provided. This target type would then allow the code generator to generate a variable declaration for the template, like Supplier<Integer> o = () -> 3;.
The text was updated successfully, but these errors were encountered:
knutwannheden
changed the title
Allow optional _target type_ to be specified for JavaTemplate
Allow optional target type to be specified for JavaTemplateOct 22, 2024
When creating a
JavaTemplate
it should be possible to optionally specify a target type (as defined in the JLS). This is for example necessary when the template expression is only a method reference or a lambda and would unlock further Refaster use cases as well as declaring some more templates as context-free (like this example).This idea would be for the
JavaTemplate.Builder
to declare a newtargetType()
method. Whether the parameter's type should be a plainString
,JavaType
, or even have both overloads would have to be explored.Note that the target type would have to be included in the cache key for the context-free template cache.
An example would be a template like
() -> 3
which would not be usable as a context-free template unless a matching target type likeSupplier<Integer>
is provided. This target type would then allow the code generator to generate a variable declaration for the template, likeSupplier<Integer> o = () -> 3;
.The text was updated successfully, but these errors were encountered: