| 本帖最后由 杨朔 于 2012-7-4 22:55 编辑 
 这个是老师的一个例子就是不懂
 第一个
 
 public class TestDemo
 {
 
 public TestDemo(int a, int b) {
 super();
 this.a = a;
 this.b = b;
 }
 private int a;
 public int b;
 public int getA() {
 return a;
 }
 public void setA(int a) {
 this.a = a;
 }
 public int getB() {
 return b;
 }
 public void setB(int b) {
 this.b = b;
 }
 
 
 
 }
 第二个
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Method;
 
 
 public class IntrospectorTest {
 
 /**
 * @param args
 */
 public static void main(String[] args)throws Exception {
 
 TestDemo t=new TestDemo(3,5);
 //                String propertrName="x";
 
 String propertyName="a";
 PropertyDescriptor pd=new PropertyDescriptor(propertyName,t.getClass());
 
 Method m=pd.getReadMethod();
 Object retVal=m.invoke(t);
 System.out.println(retVal);
 
 Method m1=pd.getWriteMethod();
 m1.invoke(t,1);
 //                System.out.println(retVal);
 
 t.getA();
 System.out.println(t.getA());
 
 
 
 }
 
 }
 
 
 |