Home > Back-end >  Novice Java reflection problem for help
Novice Java reflection problem for help

Time:12-24

Student Student=new Student ();
//Class c1=Class. Class.forname (" student ");
The Class c1=student. GetClass ();

GetName Method getName=c1. GetDeclaredMethod (" ", null);
Long startTime=System. CurrentTimeMillis ();
For (int I=0; i<=1000000000; I++)
{
GetName. Invoke (" student ", null); - this line error "error Java. Lang. IllegalArgumentException: the object is not an instance of the
- declaring class
"}
Long endTime=System. CurrentTimeMillis ();
Long finaTime=endTime - startTime;
System. The out. Println (" reflection executed "+ finaTime +" ms ");

Public class Student {
Int the age;
private String name;


Public String getName () {
return name;
}

Public void elegantly-named setName (String name) {
this.name=name;
}

}





  • Related