No, the methods which search for you expect exact parameters. So when you look for a constructor, method or field using find/search methods of the reflection API, the API uses equals()
to find matches.
If you need the same logic that the Java compiler would use, you will need to use a framework like FEST Reflect or commons beanutils. Or you must call getConstructors()
and write your own filter code.
At first glance, this seems stupid: If the Java compiler can do it, why can't the Reflection API? There are two reasons: First, the Java runtime doesn't need to search which method to call because the compiler already selected the correct method.
The second reason is that the Reflection API was always "second best". It can do everything but the goal was never to make it really easy/friendly to use (at least, that's what I think every time I use it :-)
B.class.getConstructors()
, find the ones that take exactly one argument, and check whetherA.class
isAssignableFrom
this one? – Autry