Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
FULL PRODUCT VERSION : java version "1.5.0_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08) Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows XP [Version 5.1.2600] A DESCRIPTION OF THE PROBLEM : When a generic subclass tightens a generic bound of a super class, the compiler doesn't resolve the tightened bound when when referenced across two classes. A,B,C are all generic classes that are bound to each other. A<T extends B> B<T extends C> and C is not generic. I then make genericized subclasses of these, A1, B1, C1 that tighten the bounds on the parent classes. A1 knows that it is bound to B1. B1 knows that it is bound to C1. But when you compile A1 and try to reference C1, it loses this generic binding and throws the exception. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile the testcase below and see the failure. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Successful compilation ACTUAL - Received a cannot find symbol error ERROR MESSAGES/STACK TRACES THAT OCCUR : GenericTest.java:20: cannot find symbol symbol : method someMethod() location: class GenericTest.C getB().getC().someMethod(); ^ 1 error REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- class GenericTest { static class A<T extends B> { T myB; A(T myB) {this.myB = myB;} T getB() {return myB;} } static class B<T extends C> { T myC; B(T myB) {this.myC = myC;} T getC() {return myC;} } static class C { C() {} } static class A1<T extends B1> extends A<T> { A1(T myB) {super(myB);} public void testMethod() { // This next line fails, but should work getB().getC().someMethod(); ((C1)getB().getC()).someMethod(); } } static class B1<T extends C1> extends B<T> { B1(T myC) {super(myC);} } static class C1 extends C { public void someMethod() {} } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : The workaround is that I must make a cast. ###@###.### 2005-2-10 21:42:44 GMT
|