harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Beyer" <nbe...@kc.rr.com>
Subject RE: Thanks Stepan! (was: Re: [jira] Resolved: (HARMONY-454) [classlib][luni] java.util.Set generics uplift and related changes)
Date Thu, 11 May 2006 04:38:34 GMT
Does someone understand why this works this way? This seems so odd. I know
there are quirks to the generics syntax, but this in an edge I haven't run
into yet. I haven't been able to make this one click in my head yet.

This compiles fine:
	public synchronized void putAll(Map<? extends K,? extends V> map) {
        for (Map.Entry<? extends K,? extends V> entry : map.entrySet()) {
	      ...
        }        
	}

This won't compile at all:
	public synchronized void putAll(Map<? extends K,? extends V> map) {
        Set<Map.Entry<? extends K, ? extends V>> entries = map.entrySet();
        ...
      }
The error is: Type mismatch: cannot convert from Set<Map.Entry<capture-of ?
extends K,capture-of ? extends V>> to Set<Map.Entry<? extends K,? extends
V>>
The suggested quick fix in Eclipse is "Set<?> entries = ...".

This reports a warning:
	public synchronized void putAll(Map<? extends K,? extends V> map) {
        Map<K,V> map2 = (Map<K,V>)map;
      }
The warning is: Type safety: The cast from Map<capture-of ? extends
K,capture-of ? extends V> to Map<K,V> is actually checking against the
erased type Map
The suggested quick fix in Eclipse is to the annotation:
@SuppressWarnings("unchecked").

-Nathan


> -----Original Message-----
> From: Tim Ellison [mailto:t.p.ellison@gmail.com]
> Sent: Wednesday, May 10, 2006 6:59 AM
> To: harmony-dev@incubator.apache.org
> Subject: Thanks Stepan! (was: Re: [jira] Resolved: (HARMONY-454)
> [classlib][luni] java.util.Set generics uplift and related changes)
> 
> Stepan Mishura (JIRA) wrote:
> <snip>
> > 2) To avoid casting while-loop was replaced with for-loop. Could you
> review the change?
> 
> I was scratching my head about this cast, so I was very pleased to see
> your elegant solution.
> 
> I must admit that I don't really understand why the for-loop version is
> inherently different (other than it 'hides' the casting) -- but I've
> learned a new pattern there :-)
> 
> Regards,
> Tim
> 
> --
> 
> Tim Ellison (t.p.ellison@gmail.com)
> IBM Java technology centre, UK.
> 
> 
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message