D
Daniel Hagen
Hi All,
I believe this has been answered before but I didn't find an answer to
my question, so here we are:
I am using reflection (Class.getMethod()) to find a method of a class
and execute it.
Let's assume I have the following class:
class A
{
public void v(B b)
}
I want to get (and later invoke) v .
This works fine when I am using an instance of B as parameter:
A.class.getMethod("v",new Class[]{B.class});
Whoever, when I try to user a Subclass of B, getMethod fails.
So, let's assume
class C extends B
{
[...]
}
The call
A.class.getMethod("v",new Class[]{C.class});
will fail with a NoSuchMethodException.
Am I doing something wrong, or, if this is just the way reflection
works, any suggestions for workarounds?
Thank you
Daniel
I believe this has been answered before but I didn't find an answer to
my question, so here we are:
I am using reflection (Class.getMethod()) to find a method of a class
and execute it.
Let's assume I have the following class:
class A
{
public void v(B b)
}
I want to get (and later invoke) v .
This works fine when I am using an instance of B as parameter:
A.class.getMethod("v",new Class[]{B.class});
Whoever, when I try to user a Subclass of B, getMethod fails.
So, let's assume
class C extends B
{
[...]
}
The call
A.class.getMethod("v",new Class[]{C.class});
will fail with a NoSuchMethodException.
Am I doing something wrong, or, if this is just the way reflection
works, any suggestions for workarounds?
Thank you
Daniel