small question about something I can't get my head around. I have the following:
public abstract class A
{
...
}
and an extension of this class
public class B extends A
{
...
}
Now I have a class that looks like the following
public class DoStuff extends AbstractDoStuff
{
public void doNiceStuff(B b)
{
...
}
}
It is this class' method I'm trying to invoke by reflection. However I'm trying to invoke this method from a package that is not aware of B and only knows about A. This is due to dependencies of the projects
So I have the following code that needs to find method doNiceStuff(B):
public abstract class AbstractDoStuff
{
public static Method getGetterMethod(Class<? extends AbstractDoStuff> stuffClass) throws NoSuchMethodException
{
Method method = stuffClass.getDeclaredMethod("doNiceStuff", A.class)
...
}
}
so the getDeclaredMethod should find doNiceStuff on class DoStuff but it seems that reflection isn't able to find the method using the superclass A.class. However I can't provide B.class there as the package doesn't know anything about the existence of B.
any idea if there is a way to fix this?
regards
Michael
getDeclaredMethods()), compare methods name and check if its argument extends A class.