How to get return value of invoked method?

前端 未结 2 1779
傲寒
傲寒 2021-02-20 02:00

I\'m trying to achieve some sort of reflection in java. I have:

class P {
  double t(double x) {
    return x*x;
  }

  double f(String name, double x) {
    Me         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-20 02:07

    invoke() method returns the object which is returned after that method execution! so you can try...

    Double dd = (Double)method.invoke(this,x);
    double retunedVal = dd.doubleValue();
    

提交回复
热议问题