yogendra-aurospaces / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Opportunity to fix java collections mistakes #193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Multimap.get takes a K, but containsKey takes Object.  I'm assuming this is
to be in line with java.util.Map.containsKey(Object).  Why break away from
java.util.Map.get(Object), but not fix everything.  

I think that this is a great opportunity to fix the bugs that are
Map.remove(Object), Map.containsKey(Object), Map.containsValue(Object) and
Map.get(Object).  

The fact that remove and contains take Object is a thorn to anyone doing a
refactoring and we should take the opportunity to fix it now while we have
a chance.  

Original issue reported on code.google.com by john.car...@gmail.com on 16 Jun 2009 at 5:21

GoogleCodeExporter commented 9 years ago
These methods are correct both in the JDK and here.  It must be legal to ask a 
Set<? 
extends Number> whether or not it contains 'new Integer(1)'.

Unfortunately all I have time for at the moment is to point you at this 
explanation I 
wrote long ago:

 http://smallwig.blogspot.com/2007/12/why-does-setcontains-take-object-not-e.html

I am guessing you probably will not find it convincing, but it's the best I can 
do 
for now.

Original comment by kevin...@gmail.com on 16 Jun 2009 at 5:34

GoogleCodeExporter commented 9 years ago
Yeah, I did some searching for it and realized that wildcards break these.  How 
does
Multimap.get(K) not run into this issue?

Original comment by john.car...@gmail.com on 16 Jun 2009 at 5:48

GoogleCodeExporter commented 9 years ago
get(K) returns a collection that is a "live view" -- you can add new elements 
into it 
and thus cause them to appear in the multimap.  Therefore it has to be limited 
to Ks 
only!

Sorry for my terse response last night. 

Original comment by kevin...@gmail.com on 16 Jun 2009 at 4:55

GoogleCodeExporter commented 9 years ago
Thanks for the update.  I realized that you can call get(K) on an object that 
isn't
yet in the Multimap and it will populate if you add to the returned collection. 
 I
like the idea of using IntelliJ static analysis to catch the
Collections.remove(Object) error for you when doing refactoring.  I'm going to 
try to
see if I can get findbugs to do the same thing for eclipse.

Original comment by john.car...@gmail.com on 16 Jun 2009 at 10:52