gabrielittner/auto-value-with

Don't attempt to implement non-abstract 'with' methods

Closed this issue · 1 comments

bnorm commented

Use case is a value class with a List property. I created a 'with' method to set the complete list but I wanted a 'with' method which only adds a single element to the list. Here's an example of what I'm trying to do.

@AutoValue
public abstract class Example {
    public abstract ImmutableList<String> strings();
    public abstract Example withStrings(ImmutableList<String> strings);
    public Example withString(String string) {
        return withStrings(ImmutableList.<String>builder().addAll(strings()).add(string).build());
    }
}

I could change the withString method to addString - and that's probably what I'll do in the meantime - but that departs from the pattern. Let me know if you would be willing to take a pull request for this and I can work on it myself.

It's a general AutoValue behavior to not override already implemented methods, so I'm onboard with this change.
Thanks for offering a PR, but it was a very small change and so I've done it myself.