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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to