Krzysztof Sobolewski 写道:
Spark Shen wrote:
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.
That's odd. I used a compiler this time and could not reproduce it (with
javac 1.5.0_08-b03 and quick-and-dirty from-the-scratch EnumSet impl). It
always gives me "unchecked cast" warning, no errors. Maybe I should check
out Harmony sources? :)
Hi
That's really odd. :-)
I use javac:
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
And I check out Harmony sources and run build task using ant under
command, which gives the following error prompt:
[mkdir] Created dir: C:\spark\harmony\build\classes
[javac] Compiling 3173 source files to C:\spark\harmony\build\classes
[javac]
C:\spark\harmony\modules\luni\src\main\java\java\util\MiniEnumSet.java:78:
inconvertible types
[javac] found : java.util.Collection<capture of ? extends E>
[javac] required: java.util.EnumSet<? extends E>
[javac] EnumSet<? extends E> set = (EnumSet<? extends E>)
collection;
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
BTW, before every build, I run 'ant clean' to clean all previous outputs.
Best regards
And I did not find a way to suppress the unchecked warning while
compilation succeed.
Maybe @SuppressWarnings("unchecked")? If you're absolutely sure it's OK...
BTW:
EnumSet<?> set = (EnumSet<?>)collection;
seems to compile fine, but I'm not sure it's enough for you :)
[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.
Oh, yeah... Who'd remember all that... ;)
-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]