vanessaogassawara / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Possible to clone an ImmutableList.Builder (copy constructor) #216

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It would be nice to clone an existent ImmutableList Builder,
very useful to recursive logic, while constructing trees, etc.

Therefore you could:

a) Consider adding a copy constructor to ImmutableList.Builder
i.e 
  public Builder(ImmutableList.Builder builder) {
    contents = Lists.newArrayList(builder.contents);
  }

Of course the final field 'contents' should get its default value inside
the default constructor.

b) Consider implementing the Cloneable interface.

I would prefer suggestion (a).

Original issue reported on code.google.com by ankos...@gmail.com on 10 Aug 2009 at 1:53

GoogleCodeExporter commented 8 years ago
It would be rather odd for a builder to have a copy constructor or a clone 
method. Your 
use case is somewhat unusual, and there's a simple workaround.

Instead of passing around ImmutableList.Builders and calling Builder.build(), 
your code 
can pass around ArrayLists and call ImmutableList.copyOf. Then you can copy 
those 
ArrayLists whenever necessary.

Original comment by jared.l....@gmail.com on 10 Aug 2009 at 4:07