Skip to content

Commit

Permalink
Move the toBuilder and autoToBuilder from Foo.Builder to the Foo.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 476446364
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed Sep 23, 2022
1 parent 14413dc commit c120217
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions value/userguide/builders-howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,17 @@ Instead, you could write this:
@AutoValue
public abstract class Foo {
public abstract ImmutableMap<Integer, String> map();
...

// #start
// Needed only if your class has toBuilder() method
public Builder toBuilder() {
Builder builder = autoToBuilder();
builder.mapBuilder().putAll(map());
return builder;
}

abstract Builder autoToBuilder(); // not public
// #end

@AutoValue.Builder
public abstract static class Builder {
Expand All @@ -749,19 +759,6 @@ Instead, you could write this:
setMap(mapBuilder.buildKeepingLast());
return autoBuild();
}

...

// #start
// Needed only if your class has toBuilder() method
public Builder toBuilder() {
Builder builder = autoToBuilder();
builder.mapBuilder().putAll(map());
return builder;
}

abstract Builder autoToBuilder(); // not public
// #end
}
}
```
Expand Down

0 comments on commit c120217

Please sign in to comment.