JDK-6584545 : make type of Class.getDeclaredConstructors() generic
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-07-24
  • Updated: 2012-09-28
  • Resolved: 2007-07-24
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
while for method

public Constructor<T> getConstructor(Class<?>... parameterTypes)

is "generizised" giving the return type the most possible information,
this is not true for
public Constructor<?>[] getConstructors().

i think analogously to getConstructor it should be

public Constructor<T>[] getConstructors().


JUSTIFICATION :
justification as for genierics in general: avoids casts
also since java 5 awarning is given at compile time when casting
no warnings means clean code and no fear of runtime cast exceptions.


CUSTOMER SUBMITTED WORKAROUND :
casting

Comments
EVALUATION Generic arrays are not typesafe. That's why, for example, you are not allowed to do this: new Constructor<T>[17] For the same reason, the proper generification of: Constructor[] getDeclaredConstructors() is: Constructor<?>[] getDeclaredConstructors() rather than: Constructor<T>[] getDeclaredConstructors()
24-07-2007