JAVA 中反射出类型是比较简单的,这里记录的是已知类型和方法的字符串,如何反射出此类中对应的方法,
package com.huoli.loco._test;
import java.lang.reflect.Method;
public class TestTest {
public static void main(String[] args) {
Test1 test = new Test1();
Class class1 = test.getClass();
try {
Method method = class1.getDeclaredMethod("setAppid", String.class);
method.invoke(test, "appioaiehfoiuaaodifhd");
System.out.println(test.getAppid());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Test1{
String appid;
public String getAppid() {
return appid;
}
public void setAppid(String appid) {
this.appid = appid;
}
}