-
Bug
-
Resolution: Fixed
-
P4
-
5.0, 6
-
b63
-
generic, x86
-
generic, linux
###@###.### writes:
Can you tell me why the methods in java.lang.Class that return arrays,
always return raw types instead of parameterized types?
eg. why does getInterfaces return Class[] instead of Class<?>[]
why does getClasses return Class[] instead of Class<?>[]
why does getConstructors return Constructor[] instead of Constructor<T>[]
###@###.### writes:
For the first two, this is a holdover from a time when you weren't
allowed to write arrays of generic types at all. In this case it
would have been safe to use Class<?>[]. I think we just overlooked
generifying it in this case. It should have been as you suggest.
For Constructor<T>, on the other hand, there is actually a type hole
that would be introduced by typing it that way:
Constructor<Foo>[] cfoo = Foo.class.getConstructors();
Object[] a = cfoo;
a[0] = Bar.class.getConstructor();
Foo foo = cfoo[0].newInstance(); // BOOM!
###@###.### 2005-2-16 07:04:22 GMT
Can you tell me why the methods in java.lang.Class that return arrays,
always return raw types instead of parameterized types?
eg. why does getInterfaces return Class[] instead of Class<?>[]
why does getClasses return Class[] instead of Class<?>[]
why does getConstructors return Constructor[] instead of Constructor<T>[]
###@###.### writes:
For the first two, this is a holdover from a time when you weren't
allowed to write arrays of generic types at all. In this case it
would have been safe to use Class<?>[]. I think we just overlooked
generifying it in this case. It should have been as you suggest.
For Constructor<T>, on the other hand, there is actually a type hole
that would be introduced by typing it that way:
Constructor<Foo>[] cfoo = Foo.class.getConstructors();
Object[] a = cfoo;
a[0] = Bar.class.getConstructor();
Foo foo = cfoo[0].newInstance(); // BOOM!
###@###.### 2005-2-16 07:04:22 GMT
- duplicates
-
JDK-5092092 (reflect) Class<T>.getConstructors returns Constructor[], expect Constructor<T>[
-
- Closed
-
- relates to
-
JDK-6404663 Varargs parameter in Class.getConstructor(Class...) is not generic, among others
-
- Resolved
-