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();
}
}
}
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請
點擊舉報。