| 
 
| 谁知道这个是怎么回事 ,麻烦帮忙解决下啊?复制代码public static void main(String[] args) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
        {
                Person p1 = new Person();
                
                String property1 = "name";
                
                PropertyDescriptor pd = getProperty(p1, property1);
                
                Object value = "zhangsan";
                setProperty(p1, property1, value);
        }
        private static void setProperty(Person p1, String property1, Object value)
                        throws IntrospectionException, IllegalAccessException,
                        InvocationTargetException
        {
                PropertyDescriptor pd2 = new PropertyDescriptor(property1,p1.getClass());
                Method setN = pd2.getWriteMethod();
                setN.invoke(p1, value);
        }
<font color="red">//这里,我想知道为什么按照张老师的说法去做的,而我重构出来的方法返回值是PropertyDescriptor呢?</font>
 private static PropertyDescriptor getProperty(Object p1, String property1)
          throws IntrospectionException, IllegalAccessException,
                        InvocationTargetException
        {
                PropertyDescriptor pd = new PropertyDescriptor(property1,p1.getClass());
                Method getN = pd.getReadMethod();
                Object retVal = getN.invoke(p1);
                return pd;
        }
 | 
 |