harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Krzysztof Sobolewski <jez...@interia.pl>
Subject Re: [classlib] Sun compiler change?
Date Mon, 28 Aug 2006 09:42:34 GMT
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;

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


Mime
View raw message