Hi,
I'm trying to have a (hash-based) Multimap with a (hash-based) Multiset of values for each key. See the example:
Multimap<Object, Object> mmap = Multimaps.newMultimap(
Maps.<Object, Collection<Object>>newHashMap(),
new Supplier<Collection<Object>>() {
public Collection<Object> get() {
return HashMultiset.create();
}
});
mmap.put("1", "2");
But then,
System.out.println(mmap.get("1") instanceof Multiset<?>);
//false, the returned collection is not a HashMultiset,
//but a (private) WrappedCollection
So it seems I cannot access the multiset I created? I wanted to be able to return that, as a Multiset (wrapped in Multisets.unmodifiableMultiset()). I don't want to copy it into a new Multiset each time either. Do I have any other option than switching back to Map<K, Multiset<V>>
and adding in my code the complexity that Multimap
meant to eliminate?