You misunderstood something. These are not even roughly equivalent:
Multimap<Integer, Set<String>> option4 = HashMultimap.create(); // Guava
Map<Integer, Set<String>> opt = new HashMap<Integer, Set<String>>(); //Core Java
In your example, opt4
would map a single Integer
to a Collection of Sets of Strings.
That's exactly the point of using a Multimap
, you don't have to explicitly deal with the second dimension. So in fact, the correct (equivalent) declaration would be:
SetMultimap<Integer, String> multimap = HashMultimap.create(); // Guava
and you can get a map view like this:
Map<Integer, Set<String>> mapView = multimap.asMap();
Map<Integer, Set<Set<String>>>
(I doubt that this is what you needed), or the first one should beMultimap<Integer, String>
.