Closed GoogleCodeExporter closed 9 years ago
I'd suggest using a normal mutable collection for doing this. The immutable
collection builders' reason to exist is to allow you to do things like create a
static final field in a single statement. In such situations, you can't check
the size anyway. For situations where you can check the size, the builder isn't
providing any value over a normal mutable collection, so just go ahead and use
that.
Original comment by cgdec...@gmail.com
on 9 Sep 2012 at 10:08
In these cases, I am building an immutable collection, and am not interested in
"accessing" the values as I'm building the collection. I'm simply suggesting
that a bit more information about the current state of the builder, which the
builder already has, would make my code simpler.
If it is not something that the Guava maintainers don't thinks is generally
useful, I understand. This is just a suggestion.
Original comment by d...@iq80.com
on 9 Sep 2012 at 11:27
+1 for just using a mutable collection and then doing an ImmutableXXX.copyOf
for this need.
The biggest reason I can think of for *not* supporting this feature is e.g. for
Set or SortedSet builders that might -- or might not -- eliminate duplicates on
the fly. Should the size counter include duplicates, or not?
Locking ourselves into one or the other behavior seems like a very bad idea,
especially when there's an equally simple workaround that doesn't require us to
commit to any particular builder implementation.
Original comment by wasserman.louis
on 10 Sep 2012 at 1:18
Good point. I didn't think of the case of duplicates in sets or maps. Please
close this issue.
Original comment by d...@iq80.com
on 10 Sep 2012 at 1:36
Original comment by wasserman.louis
on 10 Sep 2012 at 1:39
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:13
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:08
Original issue reported on code.google.com by
d...@iq80.com
on 9 Sep 2012 at 6:55