-
Notifications
You must be signed in to change notification settings - Fork 44
Implement instance field initializers #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/main/java/io/quarkus/gizmo2/impl/InstanceFieldCreatorImpl.java
Outdated
Show resolved
Hide resolved
ifc.withType(String.class); | ||
ifc.final_(); | ||
ifc.withInitializer(b0 -> { | ||
b0.yield(b0.withString(Constant.of("Hello")).concat(Constant.of(" world"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The yield()
call here is not entirely intuitive, but I'm not sure what we can do about that. Maybe make withInitializer()
take Function<BlockCreator, Expr>
instead of Consumer<BlockCreator>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not specific to this case... any block which has an output type (including switch expressions, ?:
, etc.) works this way. I agree it's not super intuitive and it can be easy to mess it up, but I don't see a good way of changing it in a uniform way without breaking a lot of things (or else changing all Consumer
to Function
and requiring users to return a void
constant or something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a separate discussion on that, at any rate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM baring the typos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit late but still - this is awesome!
There are too many withInitial()
overloads for my taste but that's not a big deal.
* | ||
* @param initial the initial value | ||
*/ | ||
default void withInitial(Class<?> initial) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, do you expect many Class<?>
fields? 😉
Fixes #250