import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Admin {
public Admin(){
}
private String id = "";
public String getId() {
System.out.print(id);
return id;
}
public void setId(String id) {
this.id = id;
}
@SuppressWarnings("unchecked")
public static void main(String[] args)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
String str="Admin";
Class c=Class.forName(str);
Object obj=c.newInstance();
//这里是里设置属性的值
Method m = c.getMethod("setId",new Class[]{Class.forName("java.lang.String")});
m.invoke(obj,new Object[]{"penghao122"});
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载