4

Do you have a reason why MultiMap is not completely generic?

containsEntry(Object key, Object value)
containsKey(Object key)
remove(Object key, Object value)
removeAll(Object key) 
Premraj
  • 7,802
  • 8
  • 45
  • 66
Anatoly Deyneka
  • 1,238
  • 8
  • 13

2 Answers2

4

Look at this answer which is true also for Guava's Multimap. Also, you may want read Kevin Bourrillion's blog entry (he's Guava lead dev) explaining the same issue (note that add uses generic type E):

The real difference is that add() can cause "damage" to the collection when called with the wrong type, and contains() and remove() cannot.

Uniformly, methods of the Java Collections Framework (and the Google Collections Library too) never restrict the types of their parameters except when it's necessary to prevent the collection from getting broken.

Community
  • 1
  • 1
Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
  • 1
    Guava contributor here -- this is exactly correct, and explains why it would be _bad_ to make e.g. `containsKey` only accept a `K` and not an `Object`. – Louis Wasserman Jun 19 '12 at 14:14
1

My guess its because they want a similar interface to the original java.util.Map interface

anthonyms
  • 950
  • 1
  • 10
  • 20
Peter
  • 5,728
  • 20
  • 23
  • Untrue... `Multimap` (note that it does not capitalize the m in the `map` part) does not implement the `Map` interface. – ColinD Jun 19 '12 at 14:57