###@###.### 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