Anatoly Deyneka
Anatoly Deyneka

Reputation: 1258

Generic in Google Multimap

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) 

Upvotes: 4

Views: 875

Answers (2)

Peter
Peter

Reputation: 5798

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

Upvotes: 1

Grzegorz Rożniecki
Grzegorz Rożniecki

Reputation: 28005

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.

Upvotes: 4

Related Questions