getConstructors() and unchecked conversions

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top