Java反射深度测试
2010-05-14 00:00:00 来源:WEB开发网通过反射API构造对象,并使用反射调用方式访问对象的public/private方法和字段。
package lavasoft.test;
/**
* 测试的业务类
*
* @author leizhimin 2010-5-6 20:16:10
*/
public class MyService {
private String msg;
public MyService() {
System.out.println("log: 无参构造方法lavasoft.test.MyService.MyService()被调用过了!");
}
public MyService(String msg) {
System.out.println("log: 有参构造方法lavasoft.test.MyService.MyService()被调用过了!");
this.msg = msg;
}
public String doSomething(String person, String something) {
System.out.println("log: 业务方法lavasoft.test.MyService.doSomething()被调用过了!");
return person + " is doing " + something + "! " +
"附加消息:" + msg;
}
public String getMsg() {
System.out.println("log: lavasoft.test.MyService.getMsg()被调用过了!");
return msg;
}
public void setMsg(String msg) {
System.out.println("log: lavasoft.test.MyService.setMsg()被调用过了!");
this.msg = msg;
}
private String doPrivate() {
System.out.println("log: 私有方法lavasoft.test.MyService.doPrivate()被调用过了!");
return "私有方法doPrivate()被调用了!";
}
}
更多精彩
赞助商链接