Student student =new Student();
// Class c1 =Class.forName("student");
Class c1 =student.getClass();
Method getName= c1.getDeclaredMethod("getName",null);
long startTime =System.currentTimeMillis();
for(int i =0 ;i<=1000000000;i++)
{
getName.invoke("student",null);---這行報錯“報錯 java.lang.IllegalArgumentException: object is not an instance of
----declaring class”
}
long endTime =System.currentTimeMillis();
long finaTime=endTime-startTime;
System.out.println("反射方式執行"+finaTime+"ms");
public class Student {
int age;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/239232.html
標籤:Java SE
上一篇:exe4j用win10打出來的exe程式在win7無法運行
下一篇:想安裝一個eslipse
