Próbuję osiągnąć pewnego rodzaju odbicie w Java. mam:Jak uzyskać wartość zwracaną wywołanej metody?
class P {
double t(double x) {
return x*x;
}
double f(String name, double x) {
Method method;
Class<?> enclosingClass = getClass().getEnclosingClass();
if (enclosingClass != null) {
method = enclosingClass.getDeclaredMethod(name, x);
try {
method.invoke(this, x);
} catch (Exception e) {
e.printStackTrace();
}
}
}
class o extends P {
double c() {
return f("t", 5);
}
}
Jak uzyskać wartość z nowym O() C().?
Czy sprawdziłeś zwracaną wartość 'method.invoke (this, x);'? – Apurv
tak, dzięki odpowiedzi poniżej – c4rrt3r