Community
Participate
Working Groups
Hi! The following code compiles in eclipse with a warning, but under JDK 1.5 (Update 2) it fails with an error: public class TypeConversion { public interface SuperInterface<A> { } public interface SubInterface extends SuperInterface<String> { public String getString(); } private SuperInterface< ? extends SuperInterface> x = null; public void f() { ((SubInterface) this.x).getString(); } } The problem is line "((SubInterface) this.x).getString();" **** Eclipse 3.1M6 says (warning) Type safety: The cast from TypeConversion.SuperInterface<? extends TypeConversion. SuperInterface> to TypeConversion.SubInterface is actually checking against the erased type TypeConversion.SubInterface **** JDK 1.5 javac says: imconvertible types found: TypeConversion.SuperInterface<capture of ? extends TypeConversion.SuperInterface> required: TypeConversion.SubInterface **** ciao Volker
I believe we are right. Casting to a raw type should always be fine.
This is a javac bug. See Bug Parade 6282460. Philippe, do you want to close this?
Thanks for confirming Tim. Added GenericTypeTest#test730. Closing as invalid.
The casting rules are being discussed to become more strict near provable distinctness of types. Hence, the original scenario would need to be rejected, since the bounds would be considered and thus: SuperInterface< ? extends SuperInterface> could be proven distinct from SuperInterface<String> Reopening for further consideration
Fixed along with changes released with bug 158870. Released for 3.4M3. Fixed
Verified for 3.4 M3 using build I20071029-0010.