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
Make builder constructor public #128
Make builder constructor public #128
Conversation
Useful for those cases where the subclass does not add fields (but possibly annotations and/or function overrides).
b09d8c0
to
4560427
Compare
@@ -0,0 +1,5 @@ | |||
# Generated by Maven |
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 shouldn't be in the project - please remove
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.
Actually that's a manually written comment meaning "the directory below is generated by Maven".
Let's let this sit for a bit to see if others have feedback. Regardless, this should have an option to enable it. It should not be the default. |
Agreed.
I was considering it. Things that speak against making it configurable:
Things that speak for making it configurable:
My personal take is that we should see if somebody comes up with a guarantee that an unsubclassable builder can give that a subclassable does not. |
Yes, please. |
I see that to allow a record builder to be both subclassable and fluent, it needs an additional type parameter for the setters' return type. This has ramifications for type parameters on Withers, factory methods, and such, but I don't have a useful overview. |
I got into a situation when I need a public constructor. |
@yurybubnov when I get time I can enhance this to make it optional, etc. Or maybe you can do it if you can. |
This seems to be hanging around for a while. I'm moving from Immutables.io to this as I need to do some complex Jackson serialisation. In that framework i used to augment the builder with extra helpers, e.g:
Just having both constructors on the builder as This would mean the builder is "hidden". The immutables.io library does this. |
tbh - I'm not sure what to do about this. A few bad commits got into RecordBuilder. Thankfully, they're behind options but they are there nonetheless. There's a new PR I haven't looked at. I'm not sure if it addresses this. |
I do think that this should be behind an option, |
@KangoV can you make a new PR with it behind an option? |
I'll have a go later and see how I get on. |
Anybody please feel free to take over and do as you wish. |
Please accept my apologies for lack of response. The last year or so has left me little time for side projects. I'm trying now to back to this. |
No need to apologize, I know such things happen :-) |
Should the default be public? I've had a look through the immutables.io project which I have been using and there is no option to make it private. Do you think an option is needed. I leaning towards not having one, unless someone shouts. |
It should be public if both apply:
I believe both are true. You may be reluctant to enable new use cases, since more varied use cases means more design constraints which means more design work and possibly more difficult design trade-offs. I don't see big trouble ahead in this case, so I'd do it if it were my project. |
I'd still like to be controlled by an option. This ship has sailed and I don't want to disrupt any existing use-cases. |
Not wanting to argue that the decision is already made... but making a constructor public isn't going to break any existing code, is it? |
You'd be surprised. This is more of a gut reaction based on experience. I've made what I thought were innocuous changes in this and other libraries only to be surprised by the reaction of the community. |
Replaced by #160 |
The purpose is to make record-builder fit for a slightly off-label use case:
Generate the getter/setter/equals/hashcode/toString boilerplate for our otherwise standard Java Bean classes.
We don't oppose records, actually, it's just that some libraries don't fully support using them yet.
We would like to be able to make a bean class
Foo
like this:where
FooBaseRecordBuilder
is generated from aFooBase
interface:Aside notes:
FooRecord
class.FooRecordBuilder
class, we need only the default constructor, the fields, getters/setters, and equals/hashcode/toString.stream
is a very, very appreciated addition that will help us with some other stuff. We interact with MongoDB and Jackson, and being able to iterate over whatever fields are in an entity object is a perfect match for these. (It would be nice to have a stream that returns the getters and setters, but we have to encounter that use case yet.)