运行程序,类GetMethod。为什么会出现图片中显示的问题?
class GetMethod
{
public static void main(String[] args) throws Exception
{
getMethodDemo();
}
public static void getMethodDemo() throws Exception
{
String className = "Person";
Class clazz = Class.forName(className);
String methodName = "show";
Method method = clazz.getMethod(methodName,String.class,int.class);
Object obj = clazz.newInstance();
method.invoke(obj,"lisi",20);
}
}
public class Person
{
private String name;
private int age;
public Person()
{
super();
}
public Person(String name,int age)
{
super();
this.name = name;
this.age = age;
}
public String toString()
{
return name+":"+age;
}
public void show(String name,int age)
{
System.out.println("show run name="+name+",age="+age);
}
public static void staticshow()
{
System.out.println("static run name");
}
}
|
|