package test;
import org.apache.commons.beanutils.PropertyUtils;
public class Test {
private int x;
private int y;
public int getX() { //get ,set 方法不要忘记
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
Test(){
}
Test(int x,int y){
this.x=x;
this.y=y;
}
public static void main(String[] args) {
Test t=new Test(3,8);
try {
Object k= PropertyUtils.getProperty(t, "x");//理解其反射原理
System.out.println(k.toString());//打印 值:3
} catch (Exception e) {
e.printStackTrace();
}
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。