今天做test case时遇到的一个问题。相信大家也会遇到。解决如下:
package ref;
public class ref {
public ref() {
}
private void hehe(string aa) {
system.out.println("--ref--------: " + aa);
}
public void hehe() {
system.out.println("--ref-------hh-: ");
}
}
--------class: testref------
package ref;
import java.lang.reflect.*;
public class testref {
public testref() {
}
public static void main(string[] args0) throws exception {
system.setsecuritymanager(null);
ref tr = new ref();
class vv = tr.getclass();
system.out.println("----------: " + system.getsecuritymanager());
method[] methods = vv.getmethods();
for(int i = 0; i < methods.length; i++) {
system.out.println("----------: " + methods[i].getname());
}
class worksheet = class.forname("java.lang.string");
class[] args = new class[1];
args[0] = worksheet;
method method1 = vv.getmethod("hehe", null);
method1.invoke(tr, null);
method method2 = vv.getdeclaredmethod("hehe", args);
string[] sss = {"sssss"};
method2.setaccessible(true);
method2.invoke(tr, sss);
}
}
闽公网安备 35060202000074号