Closed GoogleCodeExporter closed 8 years ago
If your multiset doesn't change after construction, you should use an
ImmutableMultiset, which has a factory method that takes varargs.
http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/col
lect/ImmutableMultiset.html#of(E...)
In most cases when people previously called Multisets.newHashMultiset(E...
elements),
the multiset is constant.
Otherwise, the following workaround isn't too cumbersome.
HashMultiset.create(Arrays.asList(elements));
With those alternatives available, we can't justify keeping
Multisets.newHashMultiset(E... elements)
Original comment by jared.l....@gmail.com
on 27 Feb 2009 at 5:45
Jan -- I'm sorry. We've had so much trouble with varargs methods causing
problems
that we're scaling back their use as much as we can. Also, we've found that the
*vast* majority of users of these varargs collection-creation methods really
did not
need a mutable collection. You may be in the minority, in which case I'm sorry
for
your trouble, but you should use the Arrays.asList() workaround. Even better,
if you
don't have nulls, use ImmutableList.of() because we're going to add enough
faux-varargs overloads to it that you can avoid warnings more of the time.
Original comment by kev...@google.com
on 27 Feb 2009 at 6:31
Thanks for your explanations. I wasn't aware of the new of(...) methods in
ImmutableMultiset etc., I think these
will work fine for most of our use cases. It's interesting that you've had
problems with varargs methods, do you
have a link to discussions about this? They do seem really useful to me, we've
ended up using these in quite a
lot of places in our code; it is a nice workaround for the lack of a literal
syntax for collections in Java.
Original comment by jan.ste...@gmail.com
on 27 Feb 2009 at 11:16
Original issue reported on code.google.com by
jan.ste...@gmail.com
on 27 Feb 2009 at 5:02