Skip to content

Instantly share code, notes, and snippets.

@relict007
Created March 15, 2017 11:49
Show Gist options
  • Save relict007/6321deba942d2f52c743da111ecada96 to your computer and use it in GitHub Desktop.
Save relict007/6321deba942d2f52c743da111ecada96 to your computer and use it in GitHub Desktop.
AutoValue with builder and an immutable list
@AutoValue.Builder
public abstract static class Builder {
public abstract List<String> list();
public abstract Builder setList(List<String> list);
abstract ListContainer autoBuild();
public ListContainer build() {
setList(ImmutableList.copyOf(list()));
return autoBuild();
}
}
@relict007
Copy link
Author

This is how you create an immutable list in java

List<Integer> items = Collections.unmodifiableList(Arrays.asList(0,1,2,3));

@relict007
Copy link
Author

relict007 commented Mar 15, 2017

Check urls:
google/auto#203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment