harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Spark Shen <smallsmallor...@gmail.com>
Subject Re: [classlib] Sun compiler change?
Date Mon, 28 Aug 2006 10:03:15 GMT
Krzysztof Sobolewski 写道:
> Spark Shen wrote:
>
>   
>> Seems that in new version of JDK, EnumSet<E> and <capture of ? extends
>> E> (E was previously stated as <E extends Enum<E>>) are not considered
>> compatible.
>> After changing
>> EnumSet<E> set = (EnumSet<E>)collection;
>> into
>> EnumSet set = (EnumSet)collection;
>> , compilation using ant in command line succeeds.
>>     
>
> ...but gives "unsafe" warnings.
>
>   
>> Would any one give a clue, why the are considered incompatible in this
>> version of JDK?
>>     
>
> Maybe a bugfix? :)
>
>
> As far as I understand generics, SomeClass<A> and SomeClass<B>, where B
> extends A, *are* incompatible (per the spec). Generic types are not polymorphic.
> The problematic line IMO should read:
>
> EnumSet<? extends E> set = (EnumSet<? extends E>)collection;
>   
Do you mean to change the problematic line into the above statement? I 
have tried this already, but this type of cast will also give a 
compilation error.
And I did not find a way to suppress the unchecked warning while 
compilation succeed.
> That's because collection seems to be an EnumSet of some unknown subclass of
> E[1] and that connot be safely converted to EnumSet<E>.
>
> [1] I guess this is in addAll() or its friends?
>   
I guess 'its friends' refers to removeAll, containsAll, and retainAll. 
:-)   But all its friends have different signature as addAll

boolean     addAll(*Collection<? extends E>* c) 

boolean     containsAll(*Collection<?>* c)
boolean     removeAll(*Collection<?>* c)
boolean     retainAll(*Collection<?>* c)
I guess you know why they are different.

So, in the implementation of all its friends, same problem is not 
encountered.
> -KS
>
>   


-- 
Spark Shen
China Software Development Lab, IBM


---------------------------------------------------------------------
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