-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement abstract "with-" methods in the value class #294
Comments
👍 👍 |
When using builders you could also have a way to create/init a builder from a value and use the builder setters to overwrite values. That said, it looks like this could be done as an extension, right? |
That's a good point, this could certainly be done with an extension. On Tue, Dec 1, 2015, 2:57 AM Thomas Broyer notifications@github.com wrote:
|
I am attempting to implement "wither" extension however I hit this block: auto/value/src/main/java/com/google/auto/value/processor/AutoValueProcessor.java Line 654 in 6d863c7
The processor does not consider methods with parameters as implementable. How would you around this limitation? |
It looks like a |
That doesn't stop you from implementing those methods in an extension. As an example |
@gabrielittner it does not stop me however I would like to get a method such as |
I've created a quick implementation https://github.com/gabrielittner/auto-value-with |
@gabrielittner awesome! It would be nice if any annotations and modifiers were retained (not force |
@eleventigers Check out @gabrielittner's auto-value-cursor implementation. The The AutoValue code you linked to, and what's given to the extensions in the list, are actual properties, i.e. the items that AutoValue is meant to create. If you have other methods they aren't properties, they're just methods, so I wouldn't expect those to appear in the |
@eleventigers Changed it. If you find anything else feel free to open an issue. |
Let's close this in favor of @gabrielittner's extension. |
It is a somewhat well-known pattern that a "withPropertyName(...)" method in an immutable class returns a copy of that instance with only that one property changed.
Users can write these themselves, but:
We could add a feature saying that you can define these "with-er" methods as abstract methods and AV will implement them.
But.... if this is a feature that 1% of all value classes will ever use, I'd probably prefer we hadn't bothered with it. (Though granted, it's not the kind of feature that means more documentation; we feel the with- example needs to be documented either way so it actually simplifies the docs.)
The text was updated successfully, but these errors were encountered: