Код: Выделить всё
{
t.getP().getName()
t.getP().getAge()
t.getP().getLocation()
}
< /code>
и следующая программа Java: < /p>
public class Test {
private Person p;
public Test(){
p = new Person("Jhon", "19", "New York", "Mathematician");
}
public Person getP() {
return p;
}
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
Test t = new Test();
// Read txt file with methods
String line1 = "t.getP().getName()";
String line2 = "t.getP().getAge()";
String line3 = "t.getP().getLocation()";
// Execute methods
Method m = t.getClass().getMethod(line1);
m.invoke(t);
}
}
< /code>
Я получаю следующую ошибку: < /p>
Exception in thread "main" java.lang.NoSuchMethodException: Test.t.getP().getName()()
at java.lang.Class.getMethod(Class.java:1786)
at Test.main(Test.java:24)
Подробнее здесь: https://stackoverflow.com/questions/729 ... le-in-java