I have a class PersonStoryDerivedTest which has an inner class "InnerClass" which has function foo in it.
if I have only an instance a of PersonStoryDerivedTest, and dont have the class name/constructor/methods... and I want to invoke foo (I know it is the second method in hte inner class). how can I do it?
public class PersonStoryDerivedTest extends PersonStoryTest {
private void thePersonRests(Integer hours) {
person.rest(hours);
}
public void ff(String g){
System.out.println("Alex");
}
public class InnerClass extends PersonStoryTest {
public void aPerson(Integer age) {
person = new Person(age);
}
public void foo(String g){
System.out.println("David");
}
}
}
public class test {
public static void main(String[] args) {
PersonStoryDerivedTest a = new PersonStoryDerivedTest();
Method[] g1 = a.getClass().getDeclaredMethods();
g1[1].invoke(a,"fff"); // print Alex (works well)
PersonStoryDerivedTest.InnerClass ab = a.new InnerClass();
Class<?>[] b = a.getClass().getDeclaredClasses();
Method[] g = b[0].getDeclaredMethods();
g[1].invoke(ab,"fff"); // print David (works well)
g[1].invoke( b[0] ,"fff"); // (does not work... how can I create the appropriate instance needed by only having b[0])
}
}
thnx