我试图在java中实现某种反射。我有:
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);
}
}
如何从 new o().c() 中获取价值?