版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/GeekLeee/article/details/85162692
package methods;
import java.lang.reflect.*;
public class MethodTableTest
{
public static void main(String[] args) throws Exception
{
try{
Method square = MethodTableTest.class.getMethod("square", double.class);
double x = 2.0;
double y = (double) square.invoke(null, x);
System.out.println(y);
}catch (Exception e){
}
}
public static double square(double x)
{
return x * x;
}
}