Say I have an interface A, and a class B that implements A.
A defines a function foo() with some default implementation, and B overrides this default implementation and implements foo() as well.
I would like to call A.foo() default implementation using invoke(obj, args) function, since I don't know what interface foo() is defined in in run time.
I know that if I wanted to use invoke on B's implementation in run time (say I have aClass that holds B) I'd do something like:
aClass.getMethod("foo", args).invoke(aClass.newInstance(), args);
How do I do the above for A.foo?
EDIT: I also only have the method's name, which I could only use to obtain its Method object, so I can't explicity call foo like A.super.foo().
SAMPLE CODE:
public interface A {
default String foo() {return "foo";}
}
public class B implements A {
}
Class<?> anInterface = Class.forName("A");
Class<?> aClass = Class.forName("B");
Method aMethod = A.getMethod("foo", null)
How do I call A.foo() with only this variables?