T
Thomas Pornin
Hello,
in Java 5, java.lang.Class and java.lang.reflect.Constructor use
generics. This is quite cool, since this avoids having to cast the
return value of newInstance().
However, Class.getConstructors() is defined to return a "Constructor[]"
and not a "Constructor<T>[]". Therefore, I get a spurious warning in my
code, which basically iterates over the constructors of a given Class<T>
object, until it finds a Constructor<T> which has the argument types I
need. This is irksome.
I understand that Class.getConstructors() is written in Java and that
having it return a Constructor<T>[] would imply some code with unchecked
conversions; but if spurious warning there must be, I would prefer to
have it in Sun's code (which I usually don't compile) instead of mine
(which I compile).
Is there an imperious reason why getConstructors() cannot return a
properly typed array ? Or is this just an overlook ? And is there a
way to make the warning disappear ?
--Thomas Pornin
in Java 5, java.lang.Class and java.lang.reflect.Constructor use
generics. This is quite cool, since this avoids having to cast the
return value of newInstance().
However, Class.getConstructors() is defined to return a "Constructor[]"
and not a "Constructor<T>[]". Therefore, I get a spurious warning in my
code, which basically iterates over the constructors of a given Class<T>
object, until it finds a Constructor<T> which has the argument types I
need. This is irksome.
I understand that Class.getConstructors() is written in Java and that
having it return a Constructor<T>[] would imply some code with unchecked
conversions; but if spurious warning there must be, I would prefer to
have it in Sun's code (which I usually don't compile) instead of mine
(which I compile).
Is there an imperious reason why getConstructors() cannot return a
properly typed array ? Or is this just an overlook ? And is there a
way to make the warning disappear ?
--Thomas Pornin