FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux lcc61.languagecomputer.com 2.4.20-31.9 #1 Tue Apr 13 18:04:23 EDT 2004 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
This problem occurs when a generic class contains a generic method with its own type variables. When the method is called on an instance of the raw type, it will not infer types for the method's type variables.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
A.java:13: incompatible types
found : java.lang.Object
required: java.lang.String
s = a3.f("test");
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class A<T> {
<U> U f(U obj) {
return obj;
}
static void test() {
String s;
A<Object> a1 = new A();
A<?> a2 = a1;
A a3 = a1;
s = a1.f("test"); // this works
s = a2.f("test"); // this works
s = a3.f("test"); // this doesn't work
}
};
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add typecasts to the method call or make sure they method is not called on a in instance of the raw type.
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux lcc61.languagecomputer.com 2.4.20-31.9 #1 Tue Apr 13 18:04:23 EDT 2004 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
This problem occurs when a generic class contains a generic method with its own type variables. When the method is called on an instance of the raw type, it will not infer types for the method's type variables.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
A.java:13: incompatible types
found : java.lang.Object
required: java.lang.String
s = a3.f("test");
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class A<T> {
<U> U f(U obj) {
return obj;
}
static void test() {
String s;
A<Object> a1 = new A();
A<?> a2 = a1;
A a3 = a1;
s = a1.f("test"); // this works
s = a2.f("test"); // this works
s = a3.f("test"); // this doesn't work
}
};
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add typecasts to the method call or make sure they method is not called on a in instance of the raw type.
- duplicates
-
JDK-6244346 Unnecessary unchecked warning (result type should not be erased)
-
- Closed
-