-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.4.0
-
generic
-
generic
The problem (which may or may not be a bug) is demonstrated by the starred line of the following program:
public class SillyInstantiator<T> {
public <U> U newObj(Class<U> klass) throws Exception {
return klass.newInstance();
}
public static void main(String[] args) throws Exception {
SillyInstantiator<Integer> si = new SillyInstantiator<Integer>();
StringBuffer i1 = si.newObj(StringBuffer.class);
SillyInstantiator rawSi = si;
StringBuffer i2 = rawSi.newObj(StringBuffer.class); // *
}
}
SillyInstantiator.java:10: incompatible types
found : java.lang.Object
required: java.lang.StringBuffer
StringBuffer i2 = rawSi.newObj(StringBuffer.class);
^
Note: SillyInstantiator.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
public class SillyInstantiator<T> {
public <U> U newObj(Class<U> klass) throws Exception {
return klass.newInstance();
}
public static void main(String[] args) throws Exception {
SillyInstantiator<Integer> si = new SillyInstantiator<Integer>();
StringBuffer i1 = si.newObj(StringBuffer.class);
SillyInstantiator rawSi = si;
StringBuffer i2 = rawSi.newObj(StringBuffer.class); // *
}
}
SillyInstantiator.java:10: incompatible types
found : java.lang.Object
required: java.lang.StringBuffer
StringBuffer i2 = rawSi.newObj(StringBuffer.class);
^
Note: SillyInstantiator.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error