Reputation: 88267
I am doing
private TreeMultimap<Integer, String> top10words =
Multimaps.synchronizedSortedSetMultimap(TreeMultimap.create());
But I get
Type mismatch: cannot convert from SortedSetMultimap to TreeMultimap
What should I be doing here? I tried casting but that failed
private TreeMultimap<Integer, String> top10words =
(TreeMultimap<Integer, String>) Multimaps.synchronizedSortedSetMultimap(TreeMultimap.create());
Upvotes: 1
Views: 113
Reputation: 28015
What you should really do is look at type hierarchy for TreeMultimap
and note that
AbstractSortedKeySortedSetMultimap
AbstractSortedSetMultimap
SortedSetMultimap
. The latter (SortedSetMultimap
) is what is returned (actually it's SynchronizedSortedSetMultimap
- an internal Guava class), not TreeMultimap
(which isn't synchronized) and that's why only
SortedSetMultimap<Integer, String> top10words =
Multimaps.synchronizedSortedSetMultimap(TreeMultimap.create());
is possible.
Upvotes: 2