FULL PRODUCT VERSION :
6.0_06, 1.6.0_10-beta-b14 and 1.7.0-ea-b25
A DESCRIPTION OF THE PROBLEM :
Code fails to compile when casting from a generic class with unbounded wildcard to a subclass.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class A<X extends Comparable<X>> {}
class B extends A<String> {}
public class Teste {
public static void main(String[] args) {
B x = new B();
A<?> y = x;
B z = (B) y;
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile (and run) nicely.
ACTUAL -
Code fails to compile.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
class A<X extends Comparable<X>> {}
class B extends A<String> {}
public class Teste {
public static void main(String[] args) {
B x = new B();
A<?> y = x;
B z = B.class.cast(y); // <-- Workaround here. Using the cast method.
}
}
6.0_06, 1.6.0_10-beta-b14 and 1.7.0-ea-b25
A DESCRIPTION OF THE PROBLEM :
Code fails to compile when casting from a generic class with unbounded wildcard to a subclass.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class A<X extends Comparable<X>> {}
class B extends A<String> {}
public class Teste {
public static void main(String[] args) {
B x = new B();
A<?> y = x;
B z = (B) y;
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile (and run) nicely.
ACTUAL -
Code fails to compile.
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
class A<X extends Comparable<X>> {}
class B extends A<String> {}
public class Teste {
public static void main(String[] args) {
B x = new B();
A<?> y = x;
B z = B.class.cast(y); // <-- Workaround here. Using the cast method.
}
}
- duplicates
-
JDK-6548436 Incorrect inconvertible types error
- Closed