- public static void main(String[] args) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- ReflectPoint rp1 = new ReflectPoint(3,5);
-
- String propertyName = "x";
- //"x"-> "X" -> "getX" ->MethodGetX ->
- PropertyDescriptor pd = new PropertyDescriptor(propertyName,rp1.getClass());
- Method methodGetX = pd.getReadMethod();
- Object retVal = methodGetX.invoke(rp1);
- //System.out.println(retVal);
- //利用JavaBean中set修改值
- Method methodSetX = pd.getWriteMethod();
- methodSetX.invoke(rp1,7);
-
- System.out.println(rp1.getX());
-
- PropertyDescriptor pd2 = new PropertyDescriptor(propertyName,rp1.getClass());
- Method methodGetX2 = pd.getReadMethod();
- Object retVal2 = methodGetX.invoke(rp1);
- System.out.println(retVal);
- }
复制代码 不知道是不是我的Myeclipse的事,为什么抽取不了
这个图片我第一次弄不知道传没传上去,说是在附件里
|
|